Opened 16 years ago

Closed 16 years ago

#10123 closed (invalid)

{% url %} template tag prepends project path to absolute url

Reported by: patrick.schoenmann@… Owned by: nobody
Component: Template system Version: 1.0
Severity: Keywords: url, reverse, template tag
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

After an upgrade to 1.0, the url template tag returns the right URL, but with the path to the django project (in the filesystem) prepended. The result is the same when using the path to the view function or a named URL pattern.

Expected:

/news/2009/

Got:

/home/myuser/django/mysite/news/2009/

Change History (4)

comment:1 by Karen Tracey, 16 years ago

This isn't happening everywhere -- a bunch of Django tests would be failing, and we'd be hearing about it from more than a single user -- so there's something specific about your setup that is coming into play here. But you don't include any details on that so I'm not sure what. My wild guess would be it may be related to changeset r8015, so you might want to read through the doc changes for that one and see if any of it is applicable to your situation.

comment:2 by patrick.schoenmann@…, 16 years ago

Needs documentation: set
Needs tests: set
Summary: {% url %} template tag prepends project path to absolute urlSolved by modifying Apache config, but might need some documentation/debugging

Thanks for your wild guess! I was able to solve the problem, which was related to mod_python...

I had a vhost with the following configuration with django 0.96:

<Location "/">
    ...
    PythonOption django.root /home/myuser/django/mysite
    ...
</Location>

I can't tell if it was even useful, but I was sure django.root was supposed to be set to django's root directory in the filesystem. (Changeset r8015 says it's in fact the root of your django site in the URL.)

As I said, {% url %} prepended django.root to the expected URL. When I clicked on the generated links, I had an error message saying 'NoneType' object is not iterable from base.py, line 77. (For some obscure reason I can't reproduce it right now.) However, the error message said ' TypeError at /news/2009 ', which was quite confusing.

I was able to solve the problem by setting django.root to nothing. Note that ' PythonOption django.root / ' won't work for a site which begins at the domain name's root, neither does commenting the line... you have to explicitly set django.root to nothing.

<Location "/">
    ...
    PythonOption django.root
    ...
</Location>

It looks like there is no consitency between some parts of django regarding the use of django.root ...

  • When preprending the value of django.root to the URL, I had an exception which seemed to come from the URL resolving (Error at /news/2009/ when the URL said /home/.../news/2009/)

Also, it would be nice to have a warning (or a link) about server configuration incompatibilities in http://docs.djangoproject.com/en/dev/releases/1.0-porting-guide/.

comment:3 by Patrick Schönmann <patrick.schoenmann@…>, 16 years ago

Summary: Solved by modifying Apache config, but might need some documentation/debugging{% url %} template tag prepends project path to absolute url

Oops ;-)

comment:4 by Jacob, 16 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top