开发者

Project name inserted automatically in url when using django template url tag

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

I have my urls named like so..开发者_StackOverflow中文版.

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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜