This is my first django project, I'm not sure why I'm getting an error 'The 'image2' attribute has no file associated with it.' when those fields are optional. How can I fix this?
model
class LinksContent(models.Model):
author = models.ForeignKey(Author, on_delete=models.DO_NOTHING, default= True)
title = models.CharField(max_length=100)
somecontent = HTMLField(blank = True)
image = models.ImageField(upload_to = 'images/%Y/%m/%d/')
image2 = models.ImageField(upload_to = 'images/%Y/%m/%d/', blank = True)
image3 = models.ImageField(upload_to = 'images/%Y/%m/%d/', blank = True)
image4 = models.ImageField(upload_to = 'images/%Y/%m/%d/', blank = True)
links = (
('faculties', 'faculties'),
('admission', 'admission'),
('resources', 'resources'),
('staff', 'staff'),
('research', 'research'),
)
file1 = models.FileField(upload_to = 'files/%Y/%m/%d/', blank = True)
section = models.CharField(max_length=13, choices=links)
is_published = models.BooleanField(default = True)
publish_date = models.DateTimeField(default = datetime.now, blank = True)
html>
{% if content %}
{% for item in content %}
<div class="theHeader">
<img class = 'header-img' src = "{{ item.image.url }}">
<div class = 'author-info'>
<img class = 'admin-img' src = "{{ item.author.image.url}}">
<p> {{ item.author}} </p>
<p> {{ item.publish_date | naturaltime}}</p>
</div>
</div>
<div id="content">
<h1>{{ item.title }}</h1>
<p>{{ item.somecontent | safe }}</p>
<div class = 'data'>
<img class = 'images' src = "{{ item.image2.url }}">
<img class = 'images' src = "{{ item.image3.url }}">
<img class = 'images' src = "{{ item.image4.url }}">
</div>
<div class = 'data'>
<p><a class = 'link' href = "{{ link.file1.url }}">Download Link</a></p>
</div>
</div>
{% endfor %}
{% else %}
<div>
<p>No data available</p>
</div>
{% endif %}
question from:
https://stackoverflow.com/questions/65861508/django-valueerror-on-optional-field 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…