I am using imagefield to render images. These are the urls;
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': site_media}),
(r'^$', 'webapp.blog.views.index'),
url(
r'^blog/view/(?P<slug>[^\.]+).html',
'webapp.blog.views.view_post',
name='view_blog_post'),
These are the views:
def index(request):
return render_to_response('index.html', {
'categories': Category.objects.all(),
'posts': Blog.objects.all()[:5]
})
def view_post(request, slug):
return render_to_response('view_post.html', {
'post': get_object_or_404(Blog, slug=slug),
})
If I call a image object in the index page with {{ posts.photos.url }} it properly maps to http://127.0.0.1/site_media/images/image.jpg. But if I call the image object on view_post template it gets mapped to http://127.0.0.1/blog/view/site_media/images/image.jpg. How can I make view_post function map image urls to the proper http://127.0.0.1/site_media/images/image.jpg url.
This is not a function of your urlconf, but how you are displaying the images in your template. You are probably doing something like this:
when you should be doing
… note the initial slash. Alternatively, if you’re using STATIC_URL or MEDIA_URL, make sure they’re defined with the initial slash in your settings.py.