Code

Opened 5 years ago

Closed 5 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: UI/UX:

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/

Attachments (0)

Change History (4)

comment:1 Changed 5 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 5 years ago by patrick.schoenmann@…

  • Needs documentation set
  • Needs tests set
  • Summary changed from {% url %} template tag prepends project path to absolute url to Solved 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 Changed 5 years ago by Patrick Schönmann <patrick.schoenmann@…>

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

Oops ;-)

comment:4 Changed 5 years ago by jacob

  • Resolution set to invalid
  • Status changed from new to closed

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.