get_script_path and request.path_info undocumented
|Reported by:||leovitch||Owned by:||anonymous|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
As near as I can tell by reading the code, the new django.path support for mod_python in 1.0 has a couple implications for code in cases where the application needs to do URL manipulations itself (I found this while testing django-cms). While the normal urlresolver takes care of anything done through reverse() or the url template tag, code that does its own manipulations on URLs need to:
- Call get_script_prefix() to get the script prefix portion to use when constructing an URL from scratch
- Use request.path_info rather than request.path when parsing an URL
Unfortunately, both of those seem to be undocumented (at least, I can't find the documentation). Shouldn't they be described?
Purely in the spirit of being helpful rather than just complaining, below is my understanding of what the documentation would be -- but I didn't write the original code, so please disregard/correct/wordsmith this as appropriate.
get_script_prefix() would be described under URL Dispatcher > Utility Methods as follows.
Normally, you should always use reverse() or permalink() to define URLs within your application. However, if your application constructs part of the URL hierarchy itself you may occasionally need to generate URLs. In that case, you need to be able to find the base URL of the Django project within its web server (normally, the urlresolver takes care of this for you). In that case, you can call get_script_prefix(), which will return the script prefix portion of the URL for your Django project. If your Django project is at the root of its webserver, this is always '/', but it can be changed for instance by using the django.root option in the modpython handler under Apache.
The path_info attribute of a request object would be documented under Request and Response Objects > HTTPRequest objects > Attributes as follows:
Under some web server configurations, the path to the page after the host name is split up into a script prefix portion and a path info portion (this happens, for example, when using the modpython handler from Apache). The path_info attribute always contains the path_info portion of the path, no matter what web server is being used. Using this instead of path can make your code much easier to move between web servers, since you won't need to care what your URL within the overall web server is.
Change History (11)
comment:3 Changed 8 years ago by
|Summary:||get_script_path and request.path_info undocumented? → get_script_path and request.path_info undocumented|
|Triage Stage:||Unreviewed → Accepted|