我的 settings.py 文件中有以下设置:
ROOT_PATH = os.path.dirname(os.path.realpath(__file__))
MEDIA_ROOT = os.path.join(ROOT_PATH,'site_media')
MEDIA_URL = 'http://xx.xxx.xx.xx:yyyy/site_media/'
And in urls.py
urlpatterns += patterns('',
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
在我的网页中:
<img border="0" width="120" align="Left" src="/site_media/images/logo.gif">
我可以在项目路径中看到该文件:
项目/site_media/images/logo.gif
但是当我在 HTML 页面中开始我的项目时,我仍然看不到图像:
Prj > python manage.py runserver xx.xxx.xx.xx:yyyy
Validating models...
0 errors found
Django version 1.3.1, using settings 'Prj.settings'
Development server is running at http://xx.xxx.xx.xx:yyyy/
Quit the server with CONTROL-C.
我不确定问题是什么,我该如何解决?
下面是我在 Firebug 中看到的请求/响应标头:
GET http://xx.xxx.xx.xx:yyyy/site_media/images/logo.gif
Response Headers
Content-Type text/html; charset=utf-8
Date Thu, 12 Apr 2012 17:00:01 GMT
Server WSGIServer/0.1 Python/2.7.2
Request Headersview source
Accept image/png,image/*;q=0.8,*/*;q=0.5
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection keep-alive
Host xx.xxx.xx.xx:yyyy
Referer http://xx.xxx.xx.xx:yyyy/
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0) Gecko/20100101 Firefox/7.0
服务器日志:
[12/Apr/2012 09:35:11] "GET /site_media/images/logo.gif HTTP/1.1" 200 122202
请注意,即使 CSS / JS 脚本也没有被加载:
GET jquery-1.4.2.js
200 OK xx.xxx.xx.xx:yyyy 119.3 KB xx.xxx.xx.xx:yyyy 6.96s
HeadersResponseCache
Response Headersview source
Content-Type text/html; charset=utf-8
Date Thu, 12 Apr 2012 17:00:03 GMT
Server WSGIServer/0.1 Python/2.7.2
Request Headersview source
Accept */*
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection keep-alive
Host xx.xxx.xx.xx:yyyy
Referer http://xx.xxx.xx.xx:yyyy/
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0) Gecko/20100101 Firefox/7.0