Currently I have the following code to handle an incoming GET request:
#view.py
def handle_request(request):
if request.method == 'GET':
<do something>
return response
this code can handle a simple GET request the form:
curl http://some_url/
But now I want to add basic http authentication:
curl --user username:password http://some_url/
I want to modify my views.py code to look like:
def handle_request(request):
if request.method == 'GET':
if username == some_hard_coded_approved_username and password == corresponding_password:
<do something>
return response
else:
response = HttpResponse("")
response.status_code = 401
return response
How do I implement this line to parse username and password from http request:
if username == some_hard_coded_approved_username and password == corresponding_password: