views:

110

answers:

2

I'm having an issue where a call to the url template tag in Django is appending the site name (I don't want it in there.)

Let's say that the site name is 'mysite'.

So for example:

<a href="{% url myapp.views.myview "myparam" %}">Link text</a>

is producing:

<a href="/mysite/foo/bar">Link text</a>

when I want it to produce:

<a href="/foo/bar">Link text</a>

My urls.py is set up like this:

from django.conf.urls.defaults import *
import mysite.myapp.views

urlpatterns = patterns('',
    (r'^/foo/bar/$', 'mysite.myapp.views.myview'),
)

Can anyone point me in the right direction?

Edit - when the site was in development, it was on a subdirectory of a test server, with the app as the subdirectory! So it was sitting on http://www.mytestserver.com/mysite. There's no caching in place, and all the references to /mysite were removed prior to going live.

+1  A: 

Are you sure, that this is the rendered version? Docs say, that an absolute url should be produced, i.e. /mysite/foo/bar. Are you checking source in the browser? Try printing out the result of render_to_string (or other rendering function you are using) and check, if there example.com is added too.

gruszczy
You're quite right, I have edited my question for clarity. Thanks for your response.
John McCollum
I sincerely don't know, what's happening. I would have to take a look at the code.
gruszczy
By the way, why do you import import mysite.myapp.views in urls.py? You don't have to do that.
gruszczy
Ok, thanks for the tip. Presumably that's because I'm passing it as a string, rather than passing the view directly?
John McCollum
Yep, you only need import, if you reference the imported name. If you put something into a string, you don't really reference it.
gruszczy
+3  A: 

Check your modpython configuration, if you've got one. There may be a line that looks like PythonOption django.root /mysite Remove that.

jcdyer
Aha - this is very likely the culprit. Thank you!
John McCollum
Nice, i'll remember too that can happen :-)
gruszczy