【发布时间】:2019-10-12 04:56:33
【问题描述】:
我正在尝试在模板中加载上传的图片。图片已正确上传,网址也正确,但我仍然收到 404 错误。错误是:- GET http://127.0.0.1:8000/media/complaints_image/motivational-inspirational-quotes-30.jpg 404(未找到)
图像存在于文件夹中:- inside the media folder image is present
模板
{% if complaint.media %}
<img src="{{ complaint.media.url }}" height="100px" width="100px" >
{% endif %}
settings.py
MEDIA_DIR = os.path.join(BASE_DIR,'media')
MEDIA_ROOT = MEDIA_DIR
MEDIA_URL = '/media/'
models.py
class Complaints(models.Model):
media = models.ImageField(upload_to='complaints_image',blank=True)
forms.py
class ComplaintForm(forms.ModelForm):
class Meta():
model = Complaint
fields = ('department','heading','text','media',)
【问题讨论】:
标签: django django-templates django-media