D
D
David52021-05-27 03:42:02
Django
David5, 2021-05-27 03:42:02

Why is the ip not coming?

I can't understand why ip usera
ip = request.META.get('HTTP_X_FORWARDED_FOR', '') doesn't come

on the old site, everything works the same, hosting is running

. What could be the problem?

def buy(request, id):
    form = AppForm(request.POST)
    if request.method == 'POST' and form.is_valid():
        new_form = form.save()
        return redirect("/orders")
    buy = Product.objects.get(id=id)
    ip = request.META.get('HTTP_X_FORWARDED_FOR', '')
    return render(request, 'shop/buy.html', {'product':buy, 'ip': ip})

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
David5, 2021-05-27
@David5

everything worked out, via request.META['HTTP_X_REAL_IP']

M
maksam07, 2021-05-27
@maksam07

If interested in a more professional solution:
https://github.com/un33k/django-ipware

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question