#35703: default URLconf detection does not take a prefix into account
-------------------------------------+-------------------------------------
     Reporter:  Maarten Breddels     |                     Type:  Bug
       Status:  new                  |                Component:
                                     |  Uncategorized
      Version:  5.1                  |                 Severity:  Normal
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 Hi,

 When Django runs onder a prefix (often described by SCRIPT_NAME for
 cgi/wsgi or root_path in asgi land) the default URLconf is not detected.
 The default page shown is then:

 {{{
 Page not found (404)
 Request Method: GET
 Request URL:    http://127.0.0.1:8000/_app/m05jjd2cn5gycxqcowk/
 Using the URLconf defined in mysite.urls, Django tried these URL patterns,
 in this order:

 admin/
 The empty path didn’t match any of these.

 You’re seeing this error because you have DEBUG = True in your Django
 settings file. Change that to False, and Django will display a standard
 404 page.
 }}}

 (in this case, the asgi root_path is `/_app/m05jjd2cn5gycxqcowk`)

 While instead, I expected to see the nice default page with
 {{{
 The install worked successfully! Congratulations!
 }}}

 The bug was introduced in
 
https://github.com/maartenbreddels/django/commit/0ecb9f6e2514cfd26a678a280d471433375101a3
 which uses `request.path == '/'` for comparison, while `request.path_info
 == '/'` was probably the intent. This commit was part of
 
https://github.com/maartenbreddels/django/commit/3f1c7b70537330435e2ec2fca9550f7b7fa4372e

 Note that `request.path` includes the prefix (SCRIPT_NAME or root_path),
 while `request.path` does not.

 I hit this bug when trying to run Django on [https://py.cafe], a platform
 that can run web applications on Pyodide.

 The project at:
 https://py.cafe/maartenbreddels/django-start-template (which includes this
 patch)
 now runs fine because I monkey-patched it (see
 https://py.cafe/files/maartenbreddels/django-start-
 template/django_patch.py), showing this is a correct fix.

 For technical reasons, we need to run under a prefix (we configure
 root_path in the asgi scope), and django was giving me a 404. This gave
 the (false) impression django did not support running under a prefix
 (StackOverflow falsely confirmed this suspicion).

 I already opened a PR at https://github.com/django/django/pull/18505
 showing the change required. I'm happy to reopen that PR and do minor work
 on it, but I don't think I'll have the bandwidth to add a test.


 Regards,

 Maarten Breddels
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35703>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701917b1f43d4-67ba6e09-1259-47e4-a5f2-a0b4e43ccc1d-000000%40eu-central-1.amazonses.com.

Reply via email to