The 'image' attribute has no file associated with it django
Question:
I am doing an ecommerce project for deployment in pythonanywhere.com, some error is coming
I would really appreciate if any one could help me to find out the problem as I am a basic learner
TIA
I have developed a online book store application with python and django,I have two MySQL tables for category and products , while running in local host it works perfectly, but the deployment in pythonanywhere only got problem in images field, also static path given
Answers:
Need to Check image is not None with if condition
<table>
<thead>
<tr>
<th>First Name</th>
<th>last Name</th>
<th>Mobile</th>
<th>E-Mail</th>
<th>City</th>
</tr>
</thead>
<tbody>
{% for i in data %}
<tr>
<td>
{% if i.image %} # need to check image is not None, this if check if image then render it else not
{{i.image.url}}
{% endif %}
</td>
<td>{{i.first_name}}</td>
<td>{{i.lastname}}</td>
<td>{{i.mobile}}</td>
<td>{{i.email}}</td>
<td>{{i.city}}</td>
</tr>
{% endfor %}
</tbody>
</table>
I found that the problem was one of the image field was none, I checked the admin panel where all the records had images except one row with image attribute empty.After adding image it works perfectly.
I am doing an ecommerce project for deployment in pythonanywhere.com, some error is coming
I would really appreciate if any one could help me to find out the problem as I am a basic learner
TIA
I have developed a online book store application with python and django,I have two MySQL tables for category and products , while running in local host it works perfectly, but the deployment in pythonanywhere only got problem in images field, also static path given
Need to Check image is not None with if condition
<table>
<thead>
<tr>
<th>First Name</th>
<th>last Name</th>
<th>Mobile</th>
<th>E-Mail</th>
<th>City</th>
</tr>
</thead>
<tbody>
{% for i in data %}
<tr>
<td>
{% if i.image %} # need to check image is not None, this if check if image then render it else not
{{i.image.url}}
{% endif %}
</td>
<td>{{i.first_name}}</td>
<td>{{i.lastname}}</td>
<td>{{i.mobile}}</td>
<td>{{i.email}}</td>
<td>{{i.city}}</td>
</tr>
{% endfor %}
</tbody>
</table>
I found that the problem was one of the image field was none, I checked the admin panel where all the records had images except one row with image attribute empty.After adding image it works perfectly.