Reversed URLs problem

7 views
Skip to first unread message

adambossy

unread,
Feb 6, 2010, 8:12:56 PM2/6/10
to Django users
Hi folks, I'm having trouble with reversed urls when they are being
called as template tags. I posted my question on Stack Overflow last
week with no adequate responses. I'll copy it here (with slight
modifications) for convenience.

http://stackoverflow.com/questions/2189119/project-name-inserted-automatically-in-url-when-using-django-template-url-tag


I have my urls named like so in my root urls.py file...

...
url(r'^login/$', 'login', name='site_login'),
...

This allows me to access /login at my site's root. I have my template
tag defined like so...

...
<a href="{% url site_login %}">
...

It works fine, except that Django automatically resolves that url as /
myprojectname/login, not /login. Both urls are accessible. Only one is
defined. Why is the projectname being inserted to the url
automagically? This occurs for all url tags, not just this one.

Thanks,
Adam

Daniel Roseman

unread,
Feb 7, 2010, 4:12:56 AM2/7/10
to Django users
On Feb 7, 1:12 am, adambossy <adambo...@gmail.com> wrote:
> Hi folks, I'm having trouble with reversed urls when they are being
> called as template tags. I posted my question on Stack Overflow last
> week with no adequate responses. I'll copy it here (with slight
> modifications) for convenience.
>
> http://stackoverflow.com/questions/2189119/project-name-inserted-auto...

>
> I have my urls named like so in my root urls.py file...
>
> ...
> url(r'^login/$', 'login', name='site_login'),
> ...
>
> This allows me to access /login at my site's root. I have my template
> tag defined like so...
>
> ...
> <a href="{% url site_login %}">
> ...
>
> It works fine, except that Django automatically resolves that url as /
> myprojectname/login, not /login. Both urls are accessible. Only one is
> defined. Why is the projectname being inserted to the url
> automagically? This occurs for all url tags, not just this one.
>
> Thanks,
> Adam

If all URLs work both with and without a prefix, it would seem that
you've somehow duplicated your URL definitions somewhere. Could you
post your entire urls.py? Preferably somewhere like dpaste.com.
--
DR.

Karen Tracey

unread,
Feb 7, 2010, 8:55:56 AM2/7/10
to django...@googlegroups.com
On Sun, Feb 7, 2010 at 4:12 AM, Daniel Roseman <dan...@roseman.org.uk> wrote:
If all URLs work both with and without a prefix, it would seem that
you've somehow duplicated your URL definitions somewhere. Could you
post your entire urls.py? Preferably somewhere like dpaste.com.

Also some information about deployment environment might be illuminating.  If not the dev server, what exactly, and what sort of config have you set up for it?

Karen 

adambossy

unread,
Feb 8, 2010, 4:06:26 PM2/8/10
to Django users
Hey folks, thanks for the responses. Your questions alone helped me
find the answer. Apparently, it was a problem with my apache2
configuration. I basically copied the directives from the django
website, with one small modification:

http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#basic-configuration

I changed <Location "/mysite"> to <Location "/"> so my Django project
would be served at my site's root directory.

I had to remove '/mysite' from the django.root option. My final output
looks like this, with no value after django.root:"

<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root
PythonDebug On
</Location>

For the record, I am running:

Django 1.0
Apache 2.2
mod_python 3.3.1 (i think... :))
Ubuntu Hardy 8.04.4

Karen Tracey

unread,
Feb 8, 2010, 5:37:45 PM2/8/10
to django...@googlegroups.com
On Mon, Feb 8, 2010 at 4:06 PM, adambossy <adam...@gmail.com> wrote:
Hey folks, thanks for the responses. Your questions alone helped me
find the answer. Apparently, it was a problem with my apache2
configuration. I basically copied the directives from the django
website, with one small modification:

http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#basic-configuration

I changed <Location "/mysite"> to <Location "/"> so my Django project
would be served at my site's root directory.

I had to remove '/mysite' from the django.root option. My final output
looks like this, with no value after django.root:"

Don't use an empty django.root, just remove it entirely. 

(I'm curious why are you using mod_python instead of mod_wsgi?)

Karen

Reply all
Reply to author
Forward
0 new messages