Django静态文件再次无法工作



我知道这个问题已经出现了好几百万次了,而且我不是django程序员的新手,最近我在django项目中处理静态文件时遇到了可怕的问题。上一次我使用1.3解决了这个问题,但现在我正在使用1.2.5版本,所有解决方案都不起作用。

所以基本上,我只在管理部分做静态工作,而在网站的其他地方没有。静态文件在K:/project/media中,我使用的是windows、python 2.7和django 1.2.5以及开发服务器。

设置:

MEDIA_ROOT = path.join(path.abspath(path.dirname(__file__)), 'media')
MEDIA_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/admin_media/'

URLconf:

urlpatterns += patterns('',
    (r'^static/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': 'K:/project/media/', 'show_indexes': True}
    ),
)

现在当我打开http://127.0.0.1:8000/static/我得到的不是静态文件列表TemplateDoesNotExist at /static/。并且模板中的导入返回类似的错误,而不是404:TemplateDoesNotExist at /static/css/global.css/。我在这里错过了什么?

编辑

完整的URL conf

from django.conf.urls.defaults import *
from django.views.generic.simple import redirect_to
from p.globals import views
from p.newsevents.feeds import ReleaseFeed
import filebrowser
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
feeds = {
    'releases': ReleaseFeed,
}
urlpatterns = patterns('',
    (r'(?P<reqPath>[w-,.]+)$', redirect_to, {'url': '%(reqPath)s/'}),
    (r'^admin/filebrowser/', include('filebrowser.urls')),
    #(r'^admin$', redirect_to, {'url': '/admin/'}),
    (r'^admin/', include(admin.site.urls)),
    (r'^tinymce/', include('tinymce.urls')),
    #(r'^about-us/$', redirect_to, {'url': '/about-us/our-story/'}),
    (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}),
    (r'^get-your-look/', include('p.getyourlook.urls')),
    (r'^about-us/', include('p.aboutus.urls')),
    (r'^our-services/', include('p.services.urls')),
    (r'^news-events/', include('p.newsevents.urls')),
    (r'^promotions/', include('p.promotions.urls')),
    (r'^careers/', include('p.careers.urls')),
    (r'^locations/', include('p.locations.urls')),
    (r'^$', views.home),
    (r'^(?P<reqPath>[w-,.]+)/', views.globals_views),
)
from django.conf import settings
urlpatterns += patterns('',
    (r'^static/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': 'K:/Kuba/Webdesign/hair/media/', 'show_indexes': True}
    ),
)

我想是因为这个:

 (r'^(?P<reqPath>[w-,.]+)/', views.globals_views),

它将拦截所有对static的请求,并调用该视图,这将导致TemplateDoesNotExist错误。在此之前放置一个静态url,或者更改此regex(以及它所引用的url)。

相关内容

  • 没有找到相关文章

最新更新