Django

Code

Ticket #1516 (reopened)

Opened 2 years ago

Last modified 8 months ago

No good access to SCRIPT_NAME

Reported by: ianb@colorstudy.com Assigned to: darrint
Milestone: Component: Core framework
Version: SVN Keywords:
Cc: ianb@colorstudy.com, sam@robots.org.uk, jumo@gmx.de, densetsu.no.ero.sennin@gmail.com, hv@tbz-pariv.de, remco@diji.biz, matt@pushcartlabs.com Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

While Django properly parses only PATH_INFO in a WSGI request, it doesn't give good access to SCRIPT_NAME, so applications cannot create proper URLs. A good application should always prefix all non-relative URLs with SCRIPT_NAME, so that should be easier to do that not to do.

In other frameworks this is sometimes done with a URL generation helper, so that url('foo', x=1) means SCRIPT_NAME+'/foo'+urllib.urlencode({'x': '1'})

Attachments

patch.txt (0.7 kB) - added by darrint on 09/14/07 18:06:43.
patch to expose mod_python SCRIPT_NAME through request.META

Change History

04/11/06 22:39:22 changed by adrian

  • component changed from Admin interface to Core framework.

04/13/06 00:30:05 changed by SmileyChris

Adrian has put a lot of work into a reverse URLconf script (see the google group discussion here: http://tinyurl.com/lbemo).

It's not finished yet, but is this a step towards what you want?

04/13/06 00:34:31 changed by ianb@colorstudy.com

If the URL reversing uses SCRIPT_NAME as the base, that would certainly help. Though the value of SCRIPT_NAME should still be available *somewhere* for people who want to generate links manually. Any app that is even slightly portable should be using SCRIPT_NAME -- directly or indirectly -- for every non-relative URL it generates.

09/26/06 08:49:41 changed by mtredinnick

  • owner changed from adrian to mtredinnick.

02/17/07 03:42:44 changed by Simon G. <dev@simon.net.nz>

  • stage changed from Unreviewed to Design decision needed.

03/10/07 05:18:40 changed by mtredinnick

  • stage changed from Design decision needed to Accepted.

We should be filling in SCRIPT_NAME. Not to do so is running against normal CGI-variables practice.

03/18/07 09:18:36 changed by anonymous

  • cc changed from ianb@colorstudy.com to ianb@colorstudy.com, sam@robots.org.uk.

09/02/07 04:50:12 changed by anonymous

  • cc changed from ianb@colorstudy.com, sam@robots.org.uk to ianb@colorstudy.com, sam@robots.org.uk, jumo@gmx.de.

09/02/07 05:09:34 changed by Densetsu no Ero-sennin <densetsu.no.ero.sennin@gmail.com>

  • cc changed from ianb@colorstudy.com, sam@robots.org.uk, jumo@gmx.de to ianb@colorstudy.com, sam@robots.org.uk, jumo@gmx.de, densetsu.no.ero.sennin@gmail.com.

09/05/07 05:11:21 changed by anonymous

Related: #285

09/14/07 17:33:43 changed by anonymous

  • owner changed from nobody to anonymous.
  • status changed from new to assigned.

09/14/07 17:34:30 changed by darrint

  • owner changed from anonymous to darrint.
  • status changed from assigned to new.

09/14/07 18:05:06 changed by darrint

It appears to me that wsgi apps get SCRIPT_NAME through meta, but this was turned off on purpose for mod_python. I'm attaching a patch for the modpython.py handler which exposes the mod_python view of SCRIPT_NAME. If this isn't what was wanted, mod_python allows setting of SCRIPT_NAME via PythonOption?.

09/14/07 18:06:43 changed by darrint

  • attachment patch.txt added.

patch to expose mod_python SCRIPT_NAME through request.META

09/14/07 18:07:53 changed by darrint

  • has_patch set to 1.

09/14/07 18:19:01 changed by Simon G. <dev@simon.net.nz>

  • stage changed from Accepted to Ready for checkin.

09/15/07 03:54:06 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to wontfix.

One good reason not to set SCRIPT_NAME for mod_python is that it's likely to be incorrect. This was confirmed recently by Graham Dumpleton.

We do want to make Django more accurate in this respect, including using SCRIPT_NAME (or a manually configured proxy) when constructing every URL and doing URL parsing. However, it needs a more holistic solution than presented here. Supplying a likely-to-be-inaccurate value in the environment is not helping the user. Closing as wontfix for that reason, although we are working on the larger problem.

09/15/07 11:17:36 changed by ianb@colorstudy.com

  • status changed from closed to reopened.
  • resolution deleted.

Can you fix SCRIPT_NAME in the mod_python adapter? SCRIPT_NAME means something very specific -- that mod_python sets it incorrectly doesn't mean you have to propagate that incorrectness or ignore its meaning.

This came up in CherryPy? too, where they didn't want to use SCRIPT_NAME because it wasn't always correct. But I don't understand why you can't just make it correct (e.g., overwriting it early on using a configuration parameter).

09/15/07 11:32:39 changed by mtredinnick

  • has_patch deleted.
  • stage changed from Ready for checkin to Accepted.

Okay, I closed this too quickly. We are going to do exactly as you say: make it work throughout (and it will be called SCRIPT_NAME). I'm actually rejecting the patch out of hand, because it's wrong. The ticket is something we're going to do. I confused problem and solution.

I need to read more carefully. Sorry.

09/26/07 14:44:46 changed by anonymous

  • cc changed from ianb@colorstudy.com, sam@robots.org.uk, jumo@gmx.de, densetsu.no.ero.sennin@gmail.com to ianb@colorstudy.com, sam@robots.org.uk, jumo@gmx.de, densetsu.no.ero.sennin@gmail.com, hv@tbz-pariv.de.

10/04/07 06:53:52 changed by anonymous

  • cc changed from ianb@colorstudy.com, sam@robots.org.uk, jumo@gmx.de, densetsu.no.ero.sennin@gmail.com, hv@tbz-pariv.de to ianb@colorstudy.com, sam@robots.org.uk, jumo@gmx.de, densetsu.no.ero.sennin@gmail.com, hv@tbz-pariv.de, remco@diji.biz.

11/27/07 14:53:39 changed by anonymous

  • cc changed from ianb@colorstudy.com, sam@robots.org.uk, jumo@gmx.de, densetsu.no.ero.sennin@gmail.com, hv@tbz-pariv.de, remco@diji.biz to ianb@colorstudy.com, sam@robots.org.uk, jumo@gmx.de, densetsu.no.ero.sennin@gmail.com, hv@tbz-pariv.de, remco@diji.biz, matt@pushcartlabs.com.

Add/Change #1516 (No good access to SCRIPT_NAME)




Change Properties
Action