views:

55

answers:

2

I run my local development server on port 8000 because my ISP blocks port 80. The problem is when using:

return HttpResponseRedirect(reverse('foobar'))

Django (for some reason) truncates the port from the URL - but it has no problem resolving it in the context of template tags e.g.: {% url foobar %}.

Since I'm attempting to reduce the number of manual changes required to deploy to our production server, I'd like to avoid hardcoding the url.

A: 

What does reverse('foobar') evaluate to at that point?

Is the correct host:port of the site entered in the sites table (Admin page is usually http://localhost:8000/admin/sites/site/ if admin is enabled)

Can you use curl -i to get the complete response from the server?

jensq
Ah - yeah that's probably worth mentioning - it resolves to http://staging.devdomain.com/foobar/ so it's resolving correctly - except it should be http://staging.devdomain.com:8000/foobar/
NFicano
Oh and I'm not using the Django Admin - so it is set to the default of example.com
NFicano
A: 

reverse() and {% url %} don't take any account of the domain and port - they just operate on the path. So the result of reverse('foobar') is the element in your urls.py that matches to 'foobar' - for example, /foo/bar/.

So something else must be changing your URL - perhaps your browser.

Daniel Roseman