[PYTHON] Use django-debug-toolbar in VirtualBox / Vagrant environment

background

--Consider using django-debug-toolbar for debugging in Django development --Record the settings you made because you were stuck using the app you are creating in the VirtualBox environment.

environment

Installation

--Installation --The installation of django was also executed automatically --Since it was an application that runs on django 1.6, reinstall django 1.6 later.

 # pip install django-debug-toolbar==1.3.0 

--Installation confirmation --Confirm that it is displayed as shown below

 # pip freeze
 Django-debug-toolbar==1.3.0

Initial setting

-Edit the following items in "$ PROJECT_DIR / setting.py" --Changed DEBUG = True --Added'debug_toolbar' to INSTALLED_APP --Added access source IP (REMOTE_ADDR) to INTERNAL_IPS

$PROJECT_DIR/setting.py


...
DEBUG = True

INSTALLED_APPS = (
...
'django.contrib.staticfiles',
'debug_toolbar',   ← django.contrib.Described on the line after static files
...
)
...
INTERNAL_IPS = ('192.168.56.1')← Define the access source IP to the server. In the case of Virtual Box, since it goes through GW, when accessing from local, the address of GW becomes the access source.

Reference: How to check REMOTE_ADDR

--Pass the value of request.META.get ('REMOTE_ADDR') as a variable and display it in the created html file.

example_view.py


from django.shortcuts import render,render_to_response
from django.template import RequestContext

def get_client_ip(request):
    return render_to_response('test.html', {
        ip_addr = request.META.get('REMOTE_ADDR'),
    }, Context_instance=RequestContext(request))

test.html


{{ ip_addr }}

Start the server

python manage.py runserver 0.0.0.0:8000

Check the page

--The toolbar for Debug is displayed on the right side of the top page of each application.

Where the installation got stuck

--It should not be displayed unless REMOTE_ADDR is added to INTERNAL_IPS. --REMOTE_ADDR is not 127.0.0.1 but the GW address of VirtualBox --Version of sqlparse (If it is another version, the error message "Exception Value: process () takes exactly 3 arguments (2 given)" is displayed)

Recommended Posts

Use django-debug-toolbar in VirtualBox / Vagrant environment
Use Anaconda in pyenv environment
(Note) Django in Vagrant environment
Use tensorflow in an environment without root
Use WebDAV in a Portable Docker environment
Use django-debug-toolbar non-locally
Use the latest pip in a virtualenv environment
Use jupyter-lab installed in python virtual environment (venv)
Use Python in Anaconda environment with VS Code
Use pydantic when reading environment variables in Python
Use os.getenv to get environment variables in Python
Use a free GPU in your favorite environment
Use config.ini in Python
Use DataFrame in Java
Use dates in Python
Use Mean in DataFrame
Use Valgrind in Python
Note: CGI (during trial and error) in Vagrant environment
Use the CASA Toolkit in your own Python environment
virtualenvwrapper in windows environment
Use ujson in requests
virtual environment in python
How to use jupyter lab in Windows 10 local environment
Use profiler in Python
Development environment in Python
Memo of Linux environment construction using VirtualBox + Vagrant on Windows 10
Let's use def in python
Use "$ in" operator with mongo-go-driver
Use let expression in Python
Use Measurement Protocol in Python
Use callback function in Python
SSH restrictions in Linux environment
Use parameter store in Python
Use HTTP cache in Python
Collaborate in a remote environment
Use regular expressions in C
Use MongoDB ODM in Python
Handle environment variables in Python
Pip install in proxy environment
Use Random Forest in Python
Use regular expressions in Python
HTTP environment variables in Flask
Use Spyder in Python IDE
Byobu crashes in pyenv environment
Use Juman ++ in server mode
Run Amazon Linux 2 in VirtualBox
· Address already in use solution
I want to run Rails with rails s even in vagrant environment
Install Networkx in Python 3.7 environment for use in malware data science books