我有一个已安装的应用程序(django_tables2),它有自己的静态文件夹,但在使用{{ STATIC_URL }}
. 阅读 django 文档后,如果我运行
>>> python manage.py findstatic django_tables2/themes/paleblue/css/screen.css
findstatic 确实在站点包的应用程序目录中正确定位了一个匹配文件。
我的相关页面模板包含:
{% block extrahead %}
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}django_tables2/themes/paleblue/css/screen.css" />
{% endblock %}
并且相关块存在于父模板中。
此页面提供于http://127.0.0.1:8000/todo/product_groups/Analytical/
。但是,在运行开发服务器时,我得到一个 404 的 css 作为它指向错误的位置:
GET /todo product_groups/Analytical/django_tables2/themes/paleblue/css/screen.css HTTP/1.1 404 2942
发生了什么,为什么服务器不遵循{{ STATIC_URL }}
与 findstatic 相同的方式?在重新设计一些 url 之前,我有同样的 static_url css 工作,但似乎无法使其在新设计中工作。任何帮助或见解将不胜感激。
来自 settings.py 的相关片段:
MEDIA_URL = '/media/'
STATIC_ROOT = 'C:/Users/riedldar/Documents/Code/Arclin/static/'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
"C:/users/riedldar/Documents/Code/Arclin/Arclin/static",
)
INSTALLED_APPS = (
....
'django.contrib.staticfiles',)
# Required for tables2
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.request",
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
来自 urls.py:
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'Arclin.views.home', name='home'),
# url(r'^Arclin/', include('Arclin.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
# Todo/Task manager
url(r'^todo/', include('todo.urls')),
# Login/out
url(r'^login/$', 'django.contrib.auth.views.login'),
url(r'^logout/$', 'Arclin.views.logout_page'),
# User Homepage
url(r'^$', 'todo.views.user_home'),
#
)
和 todo\urls.py
from django.conf.urls.defaults import *
#from models import ProductGroup
urlpatterns = patterns('',
(r'^product_groups/([\w-]+)/$', 'todo.views.items_by_product_group'),
url(r'^task/(?P<task_id>\d{1,6})$', 'todo.views.view_task', name='todo_task_detail')
)