View pictures from the template via models.FilePathField

50 views
Skip to first unread message

Federico Erbea

unread,
May 23, 2013, 3:57:02 AM5/23/13
to django...@googlegroups.com
I'm not sure this is the correct method to use, so I'm open to suggestions.
Practically I want to display the image retrieving the path where they are saved from the database.

In a class in models.py I have inserted:

locandina = models.FilePathField( path = "C:/Users/Federico.Erbea/Google Drive/Umore/apps/Database/static/Film/Locandina/", recursive=True)

In the Admin the pull-down menu perfectly recovers the files I'm interested in, allowing me to select the appropriate one
I didn't understand very well how works FilePathField, so I don't know how to pass the information to the template ... I need help, thanks

Ronny Villarroel Mendoza

unread,
May 24, 2013, 8:51:20 AM5/24/13
to django...@googlegroups.com
Hi Federico,

Maby is better idea you use the models.ImageField(upload_to= path)

ie:
locandina = models.ImageField(upload_to= path)

then in the template you can get the path:

{{ object.locandina.url }}
 
Also, you need to read some about configuration on settings.MEDIA_ROOT and settings.MEDIA_URL, for use the imageField.


Regards,
Ronny

Federico Erbea

unread,
Jun 27, 2013, 9:59:05 AM6/27/13
to django...@googlegroups.com
but ImageField, you should not use to save the imported files by users?

Reply all
Reply to author
Forward
0 new messages