擅长:python、mysql、java
<p>在设置中正确定义<code>MEDIA_ROOT</code>和{<cd2>}。在</p>
<h3>在设置.py</h3>
<pre><code>import os
CURRENT_PATH = os.path.abspath(os.path.dirname(__file__).decode('utf-8'))
MEDIA_ROOT = os.path.join(CURRENT_PATH, 'media').replace('\\','/')
MEDIA_URL = '/media/'
</code></pre>
<h3>在模型.py</h3>
^{2}$
<h3>在网址.py</h3>
<pre><code>from django.conf import settings
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': False}),
)
</code></pre>
<p>尝试使用上述代码。在</p>
<hr/>
<p>对评论中提出的问题的回答:</p>
<p>“s”将添加到模型名称中,因为将有多个模型实例。要消除它,请为模型定义<code>verbose_name</code>。在</p>
<pre><code>class stores(models.Model):
.....
storeName = models.CharField(max_length=15)
.....
class Meta:
verbose_name = 'Store'
verbose_name_plural = 'Stores'
</code></pre>