Authenticate by IP address in Django

后端 未结 6 1962
别那么骄傲
别那么骄傲 2020-12-24 15:08

I have a small Django application with a view that I want to restrict to certain users. Anyone from a specific network should be able to see that view without any further au

6条回答
  •  时光取名叫无心
    2020-12-24 15:49

    def login_by_id(request):
        ip = request.META['REMOTE_ADDR']
        try: UserProfile.objects.get(allow_ip=ip)
        except UserProfile.DoesNotExist: return HttpResponseRedirect('././')
        else:
            # auth here
    

    You need allow_ip in you UserProfile model, which save on registration or changes on edit user page

提交回复
热议问题