1 回答

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超6個(gè)贊
您的signup視圖和信號(hào)都會(huì)成為一個(gè)Profile對(duì)象,更糟糕的是,在后者中您不會(huì)鏈接到用戶。
我建議放棄創(chuàng)建Profile. 它沒(méi)有多大用處。如果您稍后編輯Profile,您應(yīng)該簡(jiǎn)單地保護(hù)它,此外您應(yīng)該確保當(dāng)您創(chuàng)建一個(gè)User對(duì)象時(shí),您只是正確地鏈接它。例如:
def signup(request):
if request.method == 'POST':
user_form = UserCreationForm(request.POST)
profile_form = ProfileForm(request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
profile_form.instance.user = user
profile = profile_form.save()
# …
# …
添加回答
舉報(bào)