sai sameer kumar
sai sameer kumar

Reputation: 1

DJANGO - how to retrieve picture from database(sqlite) to show it on html

I have loaded the pictures to database(sqlite) and now, how to get that photo in html, can you guys tell me the steps to get there, thanks in advance

I want to grab the picture from database and show it in the html.

Upvotes: 0

Views: 411

Answers (2)

Beikeni
Beikeni

Reputation: 900

Your images are stored in your static files folder and not directly in the database. I assume you are using an ImageField to store the image in your model. Something like this:

image = models.ImageField(upload_to="static/images/", null=True, blank=True)

If that's the case, in order to display it in one of your templates what you have to do is refer to the image url:

<img src="{{ mymodel.url }}" />

Upvotes: 0

Manoj Tolagekar
Manoj Tolagekar

Reputation: 1970

To show uploaded images in template:

In html file:

<img src="/media/{{image}}" /> #image is a model field name.

This is the way you can view uploaded image in template.

Upvotes: 0

Related Questions