Python论坛  - 讨论区

标题:[python-chinese] Django中request.POST.copy()的copy的意思.

2007年09月05日 星期三 21:26

beck917 beck917在gmail.com
星期三 九月 5 21:26:35 HKT 2007

   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 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年09月05日 星期三 21:39

limodou limodou在gmail.com
星期三 九月 5 21:39:07 HKT 2007

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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年09月07日 星期五 08:52

憨狗 hackgou在gmail.com
星期五 九月 7 08:52:40 HKT 2007

正解!
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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号