Answer the question
In order to leave comments, you need to log in
What should be done to display the user's ip in django?
Here is the code in the views.py file
from django.shortcuts import render
def ip(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[0]
else:
ip = request.META.get('REMOTE_ADDR')
return ip
print ("Должен быть ip но его нет",ip)
def indexx(request):
data = {"ip":ss}
return render(request, "index.html", context=data)
function ip at 0x7f293de65400
System check identified 1 issue (0 silenced).
August 30, 2019 - 14:18:16
Django version 1.11.11, using settings 'myprojectname).settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question