尝试使用特定的文件夹来显示图像,但不起作用,告诉我我做错了什么,哪里有什么不够?所有图片都在C:\dip\todo
文件夹中。使用runserver。
MEDIA_ROOT = 'C:/dip/todo/'
MEDIA_URL = 'http://127.0.0.1:8000/media/'
ADMIN_MEDIA_PREFIX = '/admin-media/'
class StatAdmin( admin.ModelAdmin ):
list_display = ( 'title', 'image')
class Stat( models.Model ):
title = models.CharField(max_length = 255,verbose_name = "Статистика" )
image = models.ImageField(upload_to='media')
def __unicode__( self ):
return u"%s" % self.title
class Meta:
verbose_name = 'Статистика'
verbose_name_plural = 'Диаграммы'
urlpatterns = patterns( '',
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.MEDIA_ROOT}), )
{% extends "admin/base.html" %}
{% load i18n %}
{% block title %}{{ title }} | Реестр инплантатов{% endblock %}
{% block branding %}
<h1 id="site-name">Реестр инплантатов</h1>
{% endblock %}
答案 0 :(得分:2)
您的媒体网址说:
MEDIA_URL = 'http://127.0.0.1:8000/media/'
但在网址中你有:
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.MEDIA_ROOT}), )
尝试将site_media
更改为media
,它应该可以正常工作