What I have done:
in models.py
:
class Image(models.Model):
img = models.ImageField(blank=True, Null=True)
And now I want to acces the image in the template. I tried it, but it didn't work: (myimg
is an instance of Image
.)
<img src="{{ myimg.img }}">
So: How do I acces the image from the template?
Another thing: when I used my model like that the images where stored at the projects root. This doesn't seem to be a good idea. Where should they be stored? And how do I store them somewhere else.
Some other little questions which deal with that problem:
- What is
MEDIA_URL
good for and how does it work? - What is
MEDIA_ROOT
good for and how does it work? - Where should files that aren't static (that means files a user or an admin uploads) be stored?