Who creates the default django welcome page?

I just installed django environment and as the tutorial said. I dialed python manager.py runserver

and he told me to open 127.0.0.1:8000

. When I open it, it worked with the correct welcome page.

But here's my question: who generates this default welcome page? Since no views.py

, and the page is urls.py

blank.

+4


source to share


3 answers


Take a look at django/core/handlers/base.py

and django/views/debug.py

. In a nutshell, if django gets 404, what if you don't have any routes then in base.py

if settings.DEBUG:
    from django.views import debug
    response = debug.technical_404_response(request, e)

      



And in debug.py look technical_404_response

andempty_urlconf

+3


source


If your urls.py is empty (nor does it contain templates to match urls) and Django is in debug mode (DEBUG = True in settings.py), then Django returns that page you see.



You can see it in the code here: https://github.com/django/django/blob/master/django/views/debug.py#L1062-L1110

+4


source


If anyone wants to return it (or reuse it), you just need to add the view debug.default_urlconf

to your urls

:

from django.views import debug

urlpatterns = [
    path('', debug.default_urlconf),
]

      

0


source







All Articles