﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35703	Default URLconf detection does not take a prefix into account	Maarten Breddels	Maarten Breddels	"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"	Bug	closed	Error reporting	5.1	Normal	fixed			Ready for checkin	1	0	0	0	0	0
