[Answered ]-Django 1.6 image upload and media path

1πŸ‘

βœ…

At first for your model you should create an image field and in there you should define where you want to upload your image:

class mymodel(models.Model):
    name = models.CharField(max_length=50)
    my_image = models.ImageField(blank=True, null=True,upload_to='/home/user/webapps/project/uploads/')

After that in your template when you want to show your image after getting your model object from your database try this:

<img src="{{ mymodel.my_image.url }}" alt="{{ mymodel.name }}" width="150" height="200" />
πŸ‘€hamidfzm

1πŸ‘

You can use:

{{ mymodel.my_image.url }}

Leave a comment