views.py 759 B

12345678910111213141516171819202122232425262728293031323334
  1. from ipaddress import ip_address
  2. from django.http import HttpResponse
  3. from django.template import loader
  4. def get_client_ip(request):
  5. x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
  6. if x_forwarded_for:
  7. ip = x_forwarded_for.split(',')[0]
  8. else:
  9. ip = request.META.get('REMOTE_ADDR')
  10. return ip
  11. #def no_cats_here():
  12. # return HttpResponse("no cats purring here, only via ipv6")
  13. def cute_cat(request):
  14. template = loader.get_template("catster/index.html")
  15. context = {}
  16. return HttpResponse(
  17. template.render(context, request)
  18. )
  19. def index(request):
  20. ip = get_client_ip(request)
  21. #if ip_address(ip).version == 4:
  22. # return no_cats_here()
  23. return cute_cat(request)