简体   繁体   English

为什么我的 html 文件没有得到我的 javascript 文件。 负载 static

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

here is my settings.py:这是我的设置.py:

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

here is the end of my html page:这是我的 html 页面的结尾:

   {% 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 .我有一个文件夹static ,里面还有两个文件夹,一个是js ,另一个是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.但是当我尝试加载它时,它总是说"GET /static/js/script.js HTTP/1.1" 404 1795我已经尝试了很多东西但它不起作用。 Someone please help.有人请帮忙。

If it is development server (ie DEBUG = True), then try this:如果它是开发服务器(即 DEBUG = True),那么试试这个:

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 .如果它是生产服务器,那么您只需删除STATICFILES_DIR The official documentation explains this more in depth. 官方文档对此进行了更深入的解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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