[b]setting.py:[/b]
HERE = os.path.dirname(os.path.abspath(__file__))
MEDIA_ROOT = os.path.join(HERE, 'static/')
MEDIA_URL = '/static/'
[b]urls.py:[/b]
(r'^static/(.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
[b]views.py:[/b]
return render_to_response(template_name, RequestContext(request))
模板里就可以直接使用{{MEDIA_URL}}来引用路径了
HERE = os.path.dirname(os.path.abspath(__file__))
MEDIA_ROOT = os.path.join(HERE, 'static/')
MEDIA_URL = '/static/'
[b]urls.py:[/b]
(r'^static/(.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
[b]views.py:[/b]
return render_to_response(template_name, RequestContext(request))
模板里就可以直接使用{{MEDIA_URL}}来引用路径了