WebFaction
Community site: login faq

Hi,

I believe I have set my django settings.py correctly to serve media and static files.

However, my {{ MEDIA_URL }} and {{ STATIC_URL }} settings are not working correctly on the root domain (index page). They are, however, working correctly on the subsequent pages.

When I Firebug mypage.com/index.html fails to show the media, lists the source as: photos/photo.jpg

When I Firebug mypage.com/sub/page.html shows the same media source correctly as: media/photos/photo.jpg

One works, one doesnt, but it is the exact same code. I have tried changing MEDIA_URL in settings.py as both absolute and relative paths. What am I missing here? Thanks for your input!

asked 20 Sep '12, 12:39

Nick_B
11914
accept rate: 0%

Have you already restarted your apache instance?

Without seeing the template, it looks like the path is hardcoded to photos on your index.html page. If you don't feel like posting your template code, feel free to open a support ticket for us to look into further for you.

(20 Sep '12, 13:11) bmeyer71 ♦♦

After reading around on the internet, the solution to my problem lied in my views. Initially my view was rendered via:

return render_to_response('index.html', {'ad_list':ad_list})

However, I needed to use RequestContext as stated in this Stack Overflow Question. Here is how it looked in the end:

return render_to_response('index.html',
                         {'list':list},
                         context_instance=RequestContext(request))

Thanks

permanent link

answered 04 Oct '12, 02:34

Nick_B
11914
accept rate: 0%

A more succinct method of obtaining a RequestContext is to use render():

from django.shortcuts import render

return render(request, 'index.html', {'list':list})
(04 Oct '12, 04:00) ryans ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×905
×32
×26
×5

question asked: 20 Sep '12, 12:39

question was seen: 7,129 times

last updated: 04 Oct '12, 04:00

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM