2014-07-09 126 views
-3
if request.method == 'POST': 
    data = request.POST.copy() # so we can manipulate data 
    try: 
     name=request.POST['useremail'].split('@')[0] 
     data['username']=getUniqueValue(User,slugify(name),field_name='useremail') 
    except: 
     data['username'] = ''.join([choice(letters) for i in xrange(20)]) 

where request.POST.COPY()有什麼用?request.POST.COPY()有什麼用?

+1

是不是評論具體解釋它? –

+1

注意,雖然這是非常糟糕的做法,但您應該在表單清理方法中進行所有這些操作。 –

+0

嗯,我不知道沒有Django,但它看起來不言自明。目標似乎有一組數據,它是所有發佈數據的副本。在這組數據中,您將操縱其中的一些數據,並且最有可能讓其他人不變。那麼我認爲你會在某處存儲這組更新的數據... –

回答

0

它的使用可以在Django文檔中找到:Request and response objects

使用Python標準庫中的copy.deepcopy()返回對象的副本。即使原件沒有,這個副本也是可變的。

+0

是啊......謝謝.. –