I have been developing my own website in Django and have come across an issue,
I have a model:
class Text_Image_Page(TrainingModulePage):
page_num = models.IntegerField(default = 0)
title = models.CharField(max_length=200)
text = models.CharField(max_length=200)
image_desc = models.CharField(max_length=200)
image = models.ImageField(upload_to=settings.MEDIA_ROOT, default = 'null')
training_module = models.ForeignKey(TrainingModule, related_name='text_image_pages', null=True)
def __str__(self):
return "Image Page"
I am using a modelForm to create this model, and everything works fine until I try to display the model in my template.
My Media Root in my settings.py is
STATIC_URL = '/static/'
MEDIA_URL = '/superchem_media/'
STATIC_ROOT = '/home/anthonycalab/webapps/superchem_static/'
MEDIA_ROOT = '/home/anthonycalab/webapps/superchem_media/'
The images are being correctly uploaded to the media root as I can see they exist via filezilla however when I go to display my image in my template:
<img src={{t.image.url}} alt="{{t.image_desc}}" style="width:304px;height:228px;">
It doesn't display the image, futhermore if I load the images direct link I get a 404 error with the following message:
Request Method: GET
Request URL: http://anthonycalab.webfactional.com/home/anthonycalab/webapps/superchem_media/41WKTB25KsL._SY395__mNsiAbb.jpg
Using the URLconf defined in superchem.urls, Django tried these URL patterns, in this order:
^training_modules/
^admin/
^accounts/
^superchem\_media\/(?P<path>.*)$
^static\/(?P<path>.*)$
The current URL, home/anthonycalab/webapps/superchem_media/41WKTB25KsL._SY395__mNsiAbb.jpg, didn't match any of these.
Any Idea's what I could be doing incorrectly?
EDIT:
The problem has been narrowed down to:
{{t.image.url}} = /home/anthonycalab/webapps/superchem_media/41WKTB25KsL._SY395__mNsiAbb.jpg
when I want
/media/[imagelink].jpg