Django 不会提供一些静态文件

Django won't serve some static files

我不确定发生了什么,但由于某些原因,django 不会提供某些脚本,并给我一个未找到的错误,鄙视显示的目录是正确的,而同一目录中的其他人没有服务问题。 这是我的文件目录结构

mysite/
├── imagenes
│   ├── migrations
│   │   └── __pycache__
│   ├── __pycache__
│   ├── recibo
│   ├── static
│   │   ├── css
│   │   └── js
│   └── templates
│       └── imagenes
├── media
│   └── recibos
│       └── 2017
│           └── 03
│               └── 10
├── mysite
│   ├── __pycache__
│   └── static
│       └── sitioI
├── static
│   ├── css
│   └── js
│       └── jquery-file-upload
└── templates
    └── registration

这是我的设置:

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

在 upload.html 中使用的静态文件,其中仅提供 lightbox.css 和 lightbox.js:

{% extends 'imagenes/base.html' %}
{% load static %}
{% block style %}
  <link rel="stlyesheet" href="{% static 'css/lightbox.css' %}">
{% endblock %}
 .
 .
 .
{% block scripts %}
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.min.js"></script>
<script src="{% static 'js/lightbox.js' %}" ></script>
<script src="{% static 'js/jquery-file-upload/vendor/jquery.ui.widget.js' %}"></script>
<script src="{% static 'js/jquery-file-upload/jquery.iframe-transport.js' %}"></script>
<script src="{% static 'js/jquery-file-upload/jquery.fileupload.js' %}"></script>
<script src="{% static 'js/upload.js' %}"></script>
{% endblock %}

这是我的 urls.py:

urlpatterns = [
    url(r'^imagenes/', include('imagenes.urls')),
    url(r'^admin/', admin.site.urls),
    url(r'^cuentas/perfil/$', editar_usuario, name='perfil'),
    url(r'^cuentas/registro/$', RegistrationView.as_view(form_class=RegistroUsuario), name='registro'), 
    url(r'^cuentas/', include('registration.backends.hmac.urls')),

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()

这是我从 运行 runserver

得到的
[13/Mar/2017 22:41:52] "GET /static/js/jquery-file-upload/jquery.fileupload.js HTTP/1.1" 404 1853
[13/Mar/2017 22:41:52] "GET /static/js/jquery-file-upload/jquery.iframe-transport.js HTTP/1.1" 404 1871
[13/Mar/2017 22:41:52] "GET /static/js/jquery-file-upload/vendor/jquery.ui.widget.js HTTP/1.1" 404 1871
[13/Mar/2017 22:41:52] "GET /static/js/upload.js HTTP/1.1" 404 1763
[13/Mar/2017 22:41:53] "GET /static/js/jquery-file-upload/vendor/jquery.ui.widget.js HTTP/1.1" 404 1871
[13/Mar/2017 22:41:53] "GET /static/js/jquery-file-upload/jquery.iframe-transport.js HTTP/1.1" 404 1871
[13/Mar/2017 22:41:53] "GET /static/js/jquery-file-upload/jquery.fileupload.js HTTP/1.1" 404 1853
[13/Mar/2017 22:41:53] "GET /static/js/upload.js HTTP/1.1" 404 1763

静态文件夹的位置有误,应该与imagenes文件夹同级。像这样

my site/
   imagenes/
         setting.py
   imaagenes2/ #beacuse i dnt khow this floder name in your project
       views.py
   static/
       css/
          main.css
       js/
          main.js

现在你可以把它放在 setting.py :

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

在你的 template :

{% load staticfiles %}
<link rel="stylesheet" src="{% static "css/main.css" %}"/>

应该可以。

如果喜欢访问 THIS LINK 以了解有关使用静态文件的更多信息