Debug on the Django error screen (browser). Enables the use of interactive shells.
⇣
Use the libraries django-extensions
and Werkzeug
.
django-extensions
extends the functionality of manage.py
, and there are many other commands.
Werkzeug is a comprehensive WSGI web application library. It started out as a simple collection of various utilities for WSGI applications and has become one of the most advanced WSGI utility libraries.
https://werkzeug.palletsprojects.com/en/1.0.x/
It's something that makes WSGI easy to use.
WSGI [1] is not a server, Python module, framework, API, or any kind of software. This is just an interface specification for the server and application to communicate.
http://wsgi.tutorial.codepoint.net/intro
It seems that there was a purpose to unify the interface because various communication standards of Python came out and there were different communication standards.
Install
$ pip install django-extensions Werkzeug
Just add to settings.py
pj_name/settings.py
.
.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions', # <-Postscript
]
.
.
For example, in a view that just displays the string ‘test’
views.py
from django.shortcuts import render
from django.http import HttpResponse
def test(request):
message = 'test'
return HttpResponse(message)
If you mistype the variable message
as mesage
⇣
views.py
from django.shortcuts import render
from django.http import HttpResponse
def test(request):
message = 'test'
return HttpResponse(mesage) # <-Typo
runserver
First, run the usual runserver.
$ python manage.py runserver
Go to http://127.0.0.1:8000/. Such an error screen.
runserver_plus
Now run runserver_plus.
Just change runserver to runserver_plus.
You will use the Debugger PIN
later.
$ python manage.py runserver_plus
...
* Debugger is active!
* Debugger PIN: 125-696-991 # <-this
It looks like this with runserver_plus.
Mouse over the code area and a terminal icon will appear. Click it.
Enter your Debugger PIN
You will be able to use an interactive shell.
Thank you for reading until the end.