Opened 21 months ago
Closed 20 months ago
#34394 closed Bug (fixed)
ASGIRequest doesn't respect settings.FORCE_SCRIPT_NAME.
Reported by: | julyzergcn | Owned by: | Sarah Boyce |
---|---|---|---|
Component: | HTTP handling | Version: | 4.1 |
Severity: | Normal | Keywords: | asgi SCRIPT_NAME |
Cc: | Carlton Gibson, Andrew Godwin, Sarah Boyce | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
For example, I have settings.FORCE_SCRIPT_NAME = '/some-prefix'
I start a django server with command: daphne django_project.asgi:application
And I navigate to the http://localhost:8000/admin/login, and see the login form action url is "/admin/login" which is wrong, which should be "/some-prefix/admin/login"
Attachments (1)
Change History (10)
comment:1 by , 21 months ago
Cc: | added |
---|---|
Component: | Core (URLs) → HTTP handling |
Summary: | django.core.handlers.asgi.ASGIRequest.script_name not work with settings.FORCE_SCRIPT_NAME → ASGIRequest doesn't respect settings.FORCE_SCRIPT_NAME. |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 21 months ago
Cc: | added |
---|
comment:3 by , 21 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
by , 21 months ago
Attachment: | Screenshot from 2023-03-16 00-43-06.png added |
---|
FORCE_SCRIPT_NAME doesn't working as expected for both ASGI and WSGI application.
comment:4 by , 21 months ago
Here, in the above attachment, I've created a simple Django app and set this FORCE_SCRIPT_NAME to /ayush
.
On running with both WSGI and ASGI applications, it shows the above-mentioned error.
Also, the queried URL is different as compared to what Django is looking for. There is the repetition of FORCE_SCRIPT_NAME
follow-up: 6 comment:5 by , 21 months ago
Seems like, FORCE_SCRIPT_NAME is also causing some issues with the WSGI application too, after someone's logout the session.
@Mariusz Felisiak, your solution for ASGI is working for me.
Please correct me, If I'm wrong...
comment:6 by , 21 months ago
Replying to Ayush Bisht:
Please correct me, If I'm wrong...
FORCE_SCRIPT_NAME
is not intended to work with dev server, see #7930. It works fine when you try with e.g. daphne
.
comment:7 by , 20 months ago
Has patch: | set |
---|---|
Owner: | changed from | to
comment:8 by , 20 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
Thanks for the report. It seems that
ASGIRequest
should takeFORCE_SCRIPT_NAME
into account (asWSGIRequest
), e.g.django/core/handlers/asgi.py
self.scope.get("root_path", "")self.get_script_prefix(scope))Would you like to prepare a patch via GitHub PR? (a regression test is required.)