我有一个具有图像源的模板,每次我运行我的 html 文件时图像都不会显示,我尝试了一些示例但没有成功,我设置了 url.py、settings.py 和 html 文件。我是 Django 的新手。
网址.py
from django.conf.urls.defaults import *
from rulebase.rulesapp.views import myview
import settings
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^rulebase/', include('rulebase.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
(r'^myview/$', myview),
(r'^media/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.MEDIA_ROOT}),
)
设置文件
MEDIA_ROOT = '/home/user/dev/Django/rulebase/media/'
MEDIA_URL = 'http://127.0.0.1:8080/media/'
ADMIN_MEDIA_PREFIX = '/media/'
HTML
<img src="{{ MEDIA_URL }}logo-on-trans.png" width="448" height="255" />