2007年09月05日 星期三 21:26
1. from django import oldforms as forms 2. from django.http import HttpResponseRedirect 3. from django.shortcuts import render_to_response 4. from django.contrib.auth.forms import UserCreationForm 5. 6. def register(request): 7. form = UserCreationForm() 8. 9. if request.method == 'POST': 10. data = request.POST.copy() 11. errors = form.get_validation_errors(data) 12. if not errors: 13. new_user = form.save() 14. return HttpResponseRedirect("/accounts/created/") 15. else: 16. data, errors = {}, {} 17. 18. return render_to_response("registration/register.html", { 19. 'form' : forms.FormWrapper(form, data, errors) 20. }) data = request.POST.copy() ,¿´²»¶®Õâ¾ä..copy()ʲôÒâ˼?? -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070905/1b868900/attachment.html
2007年09月05日 星期三 21:39
On 9/5/07, beck917 <beck917在gmail.com> wrote: > > from django import oldforms as forms > from django.http import HttpResponseRedirect > from django.shortcuts import render_to_response > from django.contrib.auth.forms import UserCreationForm > > def register(request): > form = UserCreationForm() > > if request.method == 'POST': > data = request.POST.copy() > errors = form.get_validation_errors(data) > if not errors: > new_user = form.save() > return HttpResponseRedirect("/accounts/created/") > else: > data, errors = {}, {} > > return render_to_response("registration/register.html", { > 'form' : forms.FormWrapper(form, data, errors) > }) > data = request.POST.copy() ,看不懂这句..copy()什么意思?? > 我记得POST的数据好象不能直接修改的.所以copy一下就可以修改了.POST或GET是一个自定义的dict对象,不是一个真正的dict对象. -- I like python! UliPad <>: http://code.google.com/p/ulipad/ My Blog: http://www.donews.net/limodou
2007年09月07日 星期五 08:52
正解! request.POST是只读的,所以要修改就得copy一份 limodou 写道: > On 9/5/07, beck917 <beck917 at gmail.com> wrote: >> from django import oldforms as forms >> from django.http import HttpResponseRedirect >> from django.shortcuts import render_to_response >> from django.contrib.auth.forms import UserCreationForm >> >> def register(request): >> form = UserCreationForm() >> >> if request.method == 'POST': >> data = request.POST.copy() >> errors = form.get_validation_errors(data) >> if not errors: >> new_user = form.save() >> return HttpResponseRedirect("/accounts/created/") >> else: >> data, errors = {}, {} >> >> return render_to_response("registration/register.html", { >> 'form' : forms.FormWrapper(form, data, errors) >> }) >> data = request.POST.copy() ,看不懂这句..copy()什么意思?? >> > 我记得POST的数据好象不能直接修改的.所以copy一下就可以修改了.POST或GET是一个自定义的dict对象,不是一个真正的dict对象. > > -- blog: http://hackgou.itbbq.com Email/IM : HackGou#Gmail.com PGP KeyID: hackgou#Gmail.com PGP KeyServ: subkeys.pgp.net
Zeuux © 2025
京ICP备05028076号