1
,所以我有這樣的代碼:DJANGO - 使用request.POST更改表單值?
post = request.POST.copy()
post['relationshipId'] = theRelationship.id
theStory = StoryForm(post, request = request, initial {'relationshipId' : theRelationship.id})
最初,我的代碼是這樣的:
theStory = StoryForm(request.POST, request = request, initial {'relationshipId' : theRelationship.id})
引起驗證問題。驗證器會抱怨沒有設置relationshipId。爲什麼會這樣?
編輯:第一個代碼塊正常工作,我超級高興。這個問題與第二塊代碼有關,它最初是我所擁有的(以及我剛纔花了一些時間處理的),對我而言,代理「奇怪」
'theRelationship.id'從哪裏來? – Joseph
相同的形式。嗯,發生什麼事是兩個對象的形式。關係是一個已經構建和保存的django表單。然後我粘貼上面的代碼運行。 – bharal