Image Upload in admin panel

24 views
Skip to first unread message

Surajeet Das

unread,
Feb 14, 2019, 1:37:04 PM2/14/19
to Django users
How do I upload images from admin panel and retrieve from a html page ?

Akash Purandare

unread,
Feb 14, 2019, 3:11:17 PM2/14/19
to Django users
Hey Surajeet

At first, you will need to create a model with the Field `ImageField`(do not forget to install pillow using `pip install pillow`) in the models.py of your app.
Then, you will need to register that model to admin.py of the app and then start the webserver. So, you will be able to see the model in your admin panel and thus upload the image there.
To show an image in the HTML page, you will need to create a view function and pass a context with {item: <image fetched from models>} and then write in your template code `<img src="{{item.image.url}}" />`

Regards
Akash Purandare

Ryan Nowakowski

unread,
Feb 20, 2019, 3:16:04 PM2/20/19
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages