V
V
Vladsilav2019-08-30 17:25:14
Django
Vladsilav, 2019-08-30 17:25:14

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)

And here is what the terminal shows
It should be ip but it is not
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.

I have Ubuntu 18.04.3 LTS

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2019-08-30
@dimonchik2013

come on conclusion
request.META.items()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question