Django views.py IP recorder append не работает
В моем https://fr0gs.pythonanywhere.com сайте, я создал регистратор IP-адресов для записи IP-адресов людей, заходящих на сайт. Но файл журнала пуст!
from django.shortcuts import render
from datetime import datetime
# Create your views here.
from django.http import HttpResponse
def get_ip_address(request):
""" use requestobject to fetch client machine's IP Address """
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') ### Real IP address of client Machine
return ip
def homePageView(request):
try:
alip = open('alip.txt', 'a')
alip.write(f'''{datetime.now()} : {get_ip_address(request)}
''')
alip.close()
except:
alip.close()
return HttpResponse(f'''{get_ip_address(request)} : {datetime.now()}
Hello, World!''')