Opened 5 months ago
Closed 4 months ago
#36332 closed Cleanup/optimization (fixed)
Usage notes and examples for HttpRequest.path and HttpRequest.path_info in docs are mixed up
Reported by: | Kashemir001 | Owned by: | Kashemir001 |
---|---|---|---|
Component: | Documentation | Version: | 5.2 |
Severity: | Normal | Keywords: | wsgi httprequest path_info |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Documentation for HttpRequest.get_full_path_info() gives the returning value example:
Example: "/minfo/music/bands/the_beatles/?print=true"
which implies that the script prefix part, here /minfo
, is contained in the returning value of HttpRequest.path_info
.
Now, docs for path_info itself say:
For example, if the WSGIScriptAlias for your application is set to "/minfo", then ``path`` might be "/minfo/music/bands/the_beatles/" and ``path_info`` would be "/music/bands/the_beatles/".
which implies that prefix part is not contained in HttpRequest.path_info
, but in HttpRequest.path
. This contradicts previous example.
Looking at the unit test for the subject, prefix is actually expected to be included in path_info
. Therefore, the correct example for path_info should say:
For example, if the WSGIScriptAlias for your application is set to "/minfo", then ``path`` might be "/music/bands/the_beatles/" and ``path_info`` would be "/minfo/music/bands/the_beatles/".
The usage notes for both attributes should be updated as well, so both sections updated might look like:
``HttpRequest.path`` A string representing the path to the requested page, not including the scheme, domain, script prefix, or query string. Example: "/music/bands/the_beatles/" Under some web server configurations, the portion of the URL after the host name is split up into a script prefix portion and a path info portion. The ``path`` attribute always contains the path info portion of the path, no matter what web server is being used. Using this instead of ``path_info`` can make your code easier to move between test and deployment servers. For example, If the WSGIScriptAlias for your application is set to "/minfo", then ``path`` might be "/music/bands/the_beatles/" and ``path_info`` would be "/minfo/music/bands/the_beatles/". ``HttpRequest.path_info`` The ``path_info`` attribute contains the full path, including both the script prefix portion and the path info portion of the path, unlike the ``path`` attribute. Example: "/minfo/music/bands/the_beatles/"
Change History (8)
comment:1 by , 5 months ago
Summary: | Usage notes and examples for HttpRequest.path_info and HttpRequest.get_full_path_info() in docs are mixed up → Usage notes and examples for HttpRequest.path and HttpRequest.path_info in docs are mixed up |
---|
follow-up: 3 comment:2 by , 5 months ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 5 months ago
Replying to Sarah Boyce:
Would you like to create a PR?
It might make sense to also update the linked test to be less misleading
Alright, I'll give it a go. Will switching attribute values and corresponding asserts be enough for the tests? Something about:
-
tests/requests_tests/tests.py
a b 54 54 def test_httprequest_full_path(self): 55 55 request = HttpRequest() 56 request.path = "/;some/?awful/=path/foo:bar/"57 request.path _info = "/prefix" + request.path56 request.path_info = "/;some/?awful/=path/foo:bar/" 57 request.path = "/prefix" + request.path_info 58 58 request.META["QUERY_STRING"] = ";some=query&+query=string" 59 59 expected = "/%3Bsome/%3Fawful/%3Dpath/foo:bar/?;some=query&+query=string" 60 self.assertEqual(request.get_full_path (), expected)61 self.assertEqual(request.get_full_path _info(), "/prefix" + expected)60 self.assertEqual(request.get_full_path_info(), expected) 61 self.assertEqual(request.get_full_path(), "/prefix" + expected) 62 62 63 63 def test_httprequest_full_path_with_query_string_and_fragment(self): 64 64 request = HttpRequest() 65 request.path = "/foo#bar"66 request.path _info = "/prefix" + request.path65 request.path_info = "/foo#bar" 66 request.path = "/prefix" + request.path_info 67 67 request.META["QUERY_STRING"] = "baz#quux" 68 self.assertEqual(request.get_full_path (), "/foo%23bar?baz#quux")69 self.assertEqual(request.get_full_path _info(), "/prefix/foo%23bar?baz#quux")68 self.assertEqual(request.get_full_path_info(), "/foo%23bar?baz#quux") 69 self.assertEqual(request.get_full_path(), "/prefix/foo%23bar?baz#quux") 70 70
comment:4 by , 5 months ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:5 by , 5 months ago
Has patch: | set |
---|
comment:7 by , 4 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
I agree that the examples are mixed up and we should have the following:
docs/ref/request-response.txt
usic/bands/the_beatles/?print=true"``info/music/bands/the_beatles/?print=true"``The test you have linked seems to be a misleading test, the prefix is in path rather than path info see:
Would you like to create a PR?