--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.
--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
-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.
--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 }}
python manage.py runserver 0.0.0.0:8000
--The toolbar for Debug is displayed on the right side of the top page of each application.
--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