How to use static file on css file with version in django

I need help with a problem i just ran into while working with django static file. so i downloaded this free html template that references it css style as below:

 <link rel="stylesheet" href="assets/css/vendor.bundle.css?ver=1930">
    
 <link rel="stylesheet" href="{% static 'assets/css/vendor.bundle.css?ver=1930' %}"> ```

meanwhile in django template, i know to reference static files like css and js without the ?ver=1930  as below

```

now my problem is that if i reference as

 <link rel="stylesheet" href="{% static 'assets/css/vendor.bundle.css?ver=1930' %}"> ```

it doesn't load the css and if i take away the ?ver=1930 and load it like

```

it works but my css get broken. How do i fix this problem plssss.

This has to do with your document structure. According to Django best practices, your document structure should be like this:

mysite/
    myapp/
        static/
            css
            js
            img
        __init__.py
        admin.py
        apps.py
        migrations/
        __init__.py
        models.py
        tests.py
        views.py
        manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        asgi.py
        wsgi.py

Add the css files to the static/css folder.

Your code would then be:

<link rel="stylesheet" href="{% static 'css/vendor.bundle.css' %}">

Read more on how to handle static files: Managing static files.

See how it is implemented in the polls tutorial: Django documentation

Back to Top