我在Django中遇到了一個特殊的CSS問題。Django Css問題
請參閱下面的代碼。
from django.conf.urls.defaults import patterns, include, url
from Search import settings
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('Search.views',
# Examples:
url(r'^$','select_project'),
url(r'^(?P<Project_Name>[\w \s]*)$','home'),
url(r'^(?P<Project_Name>[\w\s]*/+\w*)$','Management'),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
)
if settings.DEBUG:
urlpatterns += patterns('',
(r'^(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.MEDIA_ROOT}),
(r'^(?P<Project_Name>[\w\s]*/+[\w]*)$', 'django.views.static.serve',{'document_root': settings.MEDIA_ROOT}),
)
當我的網址--http://127.0.0.1:8000
或--http://127.0.0.1:8000/xxxxx/
,我的CSS是正確加載。
但是,當我從http://127.0.0.1:8000/xxxxx/導航到http://127.0.0.1:8000/xxxxx/abcd,那麼我的css將不會加載。請幫助
我的設置是這樣的:
MEDIA_ROOT=os.path.join(os.path.dirname(__file__), 'templates')
MEDIA_URL = '/home/'
而且,我的網控制檯說:
[06/Jan/2012 08:56:51] "GET /xxxxx/css/main.css HTTP/1.1" 404 1797
[06/Jan/2012 08:56:51] "GET /xxxxx/css/skin.css HTTP/1.1" 404 1797
[06/Jan/2012 08:56:51] "GET /xxxxx/javascript/cufon-yui.js HTTP/1.1" 404 1830
[06/Jan/2012 08:56:51] "GET /xxxxx/javascript/font.font.js HTTP/1.1" 404 1830
CSS渲染如何?是不是像'../ css/main.css'? – 2012-01-06 06:02:50
它呈現像/home/css/main.css – varadajan 2012-01-06 06:06:49