How to display an image from model
I'm newbie using django, and I neeto to display a image from
the model, I've read about serving static conten but it's not clear to
me how to do it.
This is my model:
class Author(models.Model):
first_name = models.CharField(max_length=30)
headshot = models.ImageField(upload_to='img/')
So i put in the urls.py to retrieve the image from author:
(r'^image/(\d{1,2})/$', image),
In the views:
from books.models import Author
def image(request,author_id):
autor = get_object_or_404(Author, pk=author_id)
html = "<html><body><img src=%s /></body></html>" %
(autor.headshot.url)
return HttpResponse(html)
It gets 404 error, any help?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home