I just upgraded from django 1.4.5 to django 1.5.1 and noticed that all my form processing code stopped working. In particular, form data returned using POST can no longer be found.
Django Code -
here I follow the instructions from the Django 1.5 documentation and pass the request.POST object after it was sent by the user to create an instance of LoginUserForm
class UserLoginForm(forms.Form): email = forms.EmailField(widget=forms.TextInput(attrs={'placeholder': 'Enter email', 'class': 'span4'})) password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'span4'})) def login_user(self,request): user = None if request.method == 'POST': print "post:", request.POST.items() form = UserLoginForm(request.POST) if form.is_valid(): data = form.cleaned_data email = data['email'] password = data['password'] if email and password: user_service = UserService() email = email.lower() password = string_utils.hash_password(password) user = user_service.get_by_email_and_password(password = password, email = email) return user
My form template
<form class="well" action="/web/user/login_user?next={{ next_url }}" method="post"> {% csrf_token %} <label><strong>Email:</strong></label> {{ form.email }} <label><strong>Password:</strong></label> {{ form.password }} <br /> <div class="row"> <div class="span4" style="text-align: right;"> <button type="submit" class="btn">Login</button> </div> </div> <div class="row"> <div class="span2"> <a href="/web/forgot_password" class="gray-underline" style="line-height: 25px; font-size: 12px; ">Forgot Password?</a> </div> <div class="span2" style="text-align: right;"> </div> </div> </form>
Django.1.4.5 Output -
Django version 1.4.5, using settings 'myproj.settings' post: [(u'csrfmiddlewaretoken', u'DnRTYpV1EF9XMQRAKoc3u37wya0TS3mX'), (u'password', u'abcde'), (u'email', u' john@doe.com ')] data: {'password': u'abcde', 'email': u' john@doe.com '}
Django 1.5.1 Output -
Django version 1.5.1, using settings 'myproj.settings' post: []
I looked at the release notes for Django 1.5.1 and noticed that there is some informal data that is not included in request.POST anymore .
Non-formatted data in request.POST HTTP requests will no longer include data sent via HTTP requests with non-context> content types in the header. In previous versions, data hosted with content types other than> multipart / form-data or application / x-www-form-urlencoded will still be present in the request.POST attribute. Developers who want to access the POST source data for these cases should use the request.body attribute instead.
However, given that my data is wrapped with <form></form> elements in my template and generated using the django Form class, I cannot understand why the data is not in POST? How to extract form data?