【发布时间】:2018-03-23 04:44:51
【问题描述】:
我知道这个问题已经在这里被问过好几次了。我已经搜索并阅读了许多答案,但没有任何帮助。我想,我错过了一些非常基本的东西。
在我的 settings.py 中,我有:
STATIC_URL = '/static/'
STATIC_ROOT = join(APPS_DIR, "static/")
# STATICFILES_DIRS = [join(APPS_DIR, 'static')]
MEDIA_ROOT = join(APPS_DIR, 'media')
MEDIA_URL = "/media/"
在我的 config/urls.py 中,我有:
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
我有一个位于/static/core/js/jquery_countdown/jquery.countdown.min.js 的文件,我正在尝试将其加载到模板中,如下所示:
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="{% static 'core/js/jquery_countdown/jquery.countdown.min.js' %}"> </script>
同一模板的顶部看起来像
{% extends "contest/base.html" %}
{% load static %}
这会导致以下服务器错误:
[23/Mar/2018 10:12:08] "GET /static/core/js/jquery_countdown/jquery.countdown.min.js HTTP/1.1" 404 1858
我错过了什么?
【问题讨论】:
标签: python django django-staticfiles