简体   繁体   中英

Why doesn't my html file get my javascript file. load static

here is my settings.py:

    STATIC_DIR = os.path.join(BASE_DIR,'static')
    STATIC_URL = '/static/'
    STATICFILES_DIR = [STATIC_DIR]

here is the end of my html page:

   {% load static %}
       <script src="{% static '/js/script.js' %}" type="text/javascript"></script>
   </html>
   {% endblock %}

I have a folder static and inside it, there are two more folders one is js and the other is css . But when I try to load it, it always says "GET /static/js/script.js HTTP/1.1" 404 1795 I have tried many things but it does not work. Someone please help.

If it is development server (ie DEBUG = True), then try this:

STATIC_URL = '/static/'
STATICFILES_DIRS = (
    'static',
)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

If it is production server, then you simply remove the STATICFILES_DIR . The official documentation explains this more in depth.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM