1👍
✅
remove self from process_request and pass request argument to func()
def basic_auth(func):
def process_request(request):
if request.META.get("HTTP_AUTHORIZATION"):
encoded_auth = request.META.get("HTTP_AUTHORIZATION")
encoded_auth = encoded_auth[6:]
auth = base64.b64decode(encoded_auth)
auth_email = auth.split(":")[0]
auth_password = auth.split(":")[1]
if (auth_email == settings.BASIC_AUTH_EMAIL) and (auth_password == settings.EMAIL_HOST_PASSWORD):
func(request)
else:
return HttpResponseForbidden("Forbidden")
return process_request
for better understanding of function decorator:
http://thecodeship.com/patterns/guide-to-python-function-decorators/
1👍
You are not passing request as an argument to func(). Try with this:
if (auth_email == settings.BASIC_AUTH_EMAIL) and (auth_password == settings.EMAIL_HOST_PASSWORD):
func(request)
else:
return HttpResponseForbidden("Forbidden")
- [Answered ]-(beginner) First Django Web App – models.py
- [Answered ]-Multiply Django Apache servers
- [Answered ]-How to make a Model with a Many-to-Many relationship as Categories (i.e) rock ,Country, Blues, and Pop
- [Answered ]-Django getting database fields with one query
- [Answered ]-How to test a Django view which has transaction.atomic(using=myDb)?
Source:stackexchange.com