views:

160

answers:

2

I am applying the 'url' template tag to all links in my current Django project.

I have my urls named like so...

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. Why? Is there an option to remove the projectname? This occurs for all url tags, not just this one.

A: 

In your url conf django encounters this url pattern earlier than the other one.

Since url resolution is done one by one, just move around the main login before the include within the main urls.py

Lakshman Prasad
There is only one url pattern. The second one, "/myprojectname/login", is being created *magically*. I'm trying to figure out why this magic occurs and whether there's an option to change it.
thebossman
+2  A: 

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 to 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

Copied from here: http://groups.google.com/group/django-users/msg/5e79ed1e694a3776

thebossman