I am using a form from my Apache/PHP Server and Django to handle all my posts/requests. How can I set it so that a field is not set it won’t cause an error?
PHP Form:
<form action="http://www.mydomain.com:8003/login/" method="post">
<input type="text" name="email" id="email"><br>
<input type="text" name="password" id="password"><br>
<input type="checkbox" name="remember"><br>
<input type="submit" value="send" id="send">
</form>
Django:
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def index(request):
if request.method == 'POST':
post = request.POST
email = post['email']
pass = post['password']
remember = post['remember']
if remember:
expire_v = 30
else:
expire_v = None
response = HttpResponse(email)
response.set_cookie('emailaddress', email, max_age=expire_v)
response.set_cookie('password', pass, max_age=expire_v)
return response
The problem is if remember isn’t checked than it causes an error.
There is an awful lot wrong with this code and without knowing the error: Try use defaults when you are fetching the parameters from the request