Django never ceases to baffle me with completely uncalled for actions. I
I have a media article template which is derived from a Django model. All works a treat and looks awesome, except for the images.
One minute they’re present, the next Django needs a new glasses prescription as it suddenly decides it can’t see the image which is blatantly in the directory with which I have set up.
Here’s my full reproduceable example and see if anyone can figure out why Django decides its not going to show the image:
#models.py
from django.db import models
import uuid
# Create your models here.
....
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
article_image = models.ImageField(upload_to='media/assets')
....
In my views.py
, I have the following:
def details(request, uuid):
articles = MediaModule.objects.all().values()
article = get_object_or_404(MediaModule, uuid=uuid)
title = article.article_headline
return render(request, 'media-article.html', {'article': article, 'title':title, 'articles':articles})
The file directory is as follows:
Root|
|- media
|- template
| - media-article.html
|- media
| - assets
| - image.jpg
#media-article.html
<img src="{{article.article_image}}" alt="{{article.article_image}}"/>
Just why does Django think “Ah-hah, there’s the image!”, and then says “Actually, I’m going to deliberate pretend the image is not there, because I am going to be difficult now”
Why does it do it? What is the possible conceivable reason is there as to why Django decided it’s just not going to show the image.
Why?
Just why?
In addition to this, why does Django see fit to copy the image in the directory and append a load of random letters and number to it?