how to get POST data in django 1.3

后端 未结 4 982
感情败类
感情败类 2021-02-06 02:49

Hey, I am following this tutorial to learn to make a wiki page with Django. However, it is made in django 0.96 and I use Django 1.3 so there are some things that are different.

4条回答
  •  萌比男神i
    2021-02-06 03:43

    You will need the {% csrf_token %} template tag in between your tags as well as including

       django.middleware.csrf.CsrfViewMiddleware
       django.middleware.csrf.CsrfResponseMiddleware
    

    in your MIDDLEWARE_CLASSES in the applications settings.py

    Adding some example post data handling:

    This is an example of one of the times I am using POST data in a view. I will generally rely on the form class to do verification via the cleaned_data array.

    if request.method == 'POST':
            form = ForgotPassword(data=request.POST)
            if form.is_valid():
                try:
                    new_user = backend.forgot_password(request, **form.cleaned_data)
                except IntegrityError:
                    context = {'form':form}
                    form._errors[''] = ErrorList(['It appears you have already requested a password reset, please \
                    check ' + request.POST['email2'] + ' for the reset link.'])
                    return render_template(request,'passwordReset/forgot_password.html',context)
                if success_url is None:
                    to, args, kwargs = backend.post_forgot_password(request, new_user)
                    return redirect(to, *args, **kwargs)
                else:
                    return redirect(success_url)
    

提交回复
热议问题