於是跑進這個問題,即媒體的網址不希望加載/工作至今我urls.py是建立像這樣Django的媒體不加載
if settings.DEBUG:
urlpatterns += patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),)
我的設置。 PY像這樣
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = 'http:/localhost:8000/admin-media/'
我的HTML模板,像這樣
<link rel="stylesheet" href="/media/css/template.css" type="text/css" />
<link rel="stylesheet" href="/media/css/nivo-slider.css" type="text/css" />
<script type="text/javascript" src="/media/js/jquery-1.4.3.min.js"></script>
<script type="text/javascript" src="/media/js/jquery.nivo.slider.pack.js"></script>
每當我http://localhost:8000/media/css/template.css型我得到
AttributeError at /media/css/template.css/
'str' object has no attribute 'resolve'
,並在我的Django的服務器登錄以下
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 283, in run
self.result = application(self.environ, self.start_response)
File "C:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 272, in __call__
response = self.get_response(request)
File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 169, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 218, in handle_uncaught_exception
return callback(request, **param_dict)
File "C:\Python27\lib\site-packages\django\utils\decorators.py", line 93, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\defaults.py", line 30, in server_error
t = loader.get_template(template_name) # You need to create a 500.html template.
File "C:\Python27\lib\site-packages\django\template\loader.py", line 157, in get_template
template, origin = find_template(template_name)
File "C:\Python27\lib\site-packages\django\template\loader.py", line 138, in find_template
raise TemplateDoesNotExist(name)
TemplateDoesNotExist: 500.html
當我鍵入http://localhost:8000/home/我的頁面加載,但沒有我的CSS或JavaScript加載..
這很奇怪,因爲我的urls.py有以下URL模式=模式( '',( '^家/ $',master_page), ( '^頁腳/ $'), ) – Ayo 2012-03-28 21:15:07