Hi there,

I'm trying to create a photo gallery by storing photos in a gallery 
database and pulling them out when appropriate.

However, I ran into the problem of how to publicly expose the pictures in 
urls. In my template, I return a the url of the photo which turns out to be 
images/photo.jpg. However in my development server, when I put in the url 
192.0.0.1:8000/images/photo.jpg, I can't view the image. Is there any way 
to make the url/image accessible through the url provided by the object 
without manually tampering with urls.py? If not, why does Django provide 
the .url field? Is this the only a recommended url field then?

My View:

def gallery(request):
    base_gallery = gall.objects.get(name="base")
    base_list = base_gallery.photos.all()
    return render_to_response('gallery.html',
        {'list_of_images':base_list},
        context_instance = RequestContext(request),
    )

Template:

{% extends "index.html" %}{% block body_content %}
{% for photo in list_of_images %}
    {{ photo.image.url }}{% endfor %}{% endblock %}

Model:

from django.db import models
class photo(models.Model):
    name = models.CharField(max_length=50,blank=True,null=True)
    source_descr = models.CharField(max_length=100,blank=True,null=True)
    image = models.ImageField(upload_to='images')

class gallery(models.Model):
    name = models.CharField(max_length=50)
    photos = models.ManyToManyField(photo)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/crmJYuBCBfgJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to