What is the URL you are trying to reach? From what you've provided here,
the author id would be 1-2 digits and would need to match a valid Author
record in the database. Any chance that either of those are incorrect
for your request? (also make sure your request URL ends with a forward
slash)
On 11/21/2011 11:53 AM, antonio wrote:
> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.