第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

我無(wú)法通過(guò) Django 將表單內(nèi)容保存在數(shù)據(jù)庫(kù)中

我無(wú)法通過(guò) Django 將表單內(nèi)容保存在數(shù)據(jù)庫(kù)中

哈士奇WWW 2023-07-11 10:51:41
大家好,我正在嘗試在我的數(shù)據(jù)庫(kù)中保存表單 my models.pyclass customer(models.Model):    customerid = models.CharField(default=str(uuid.uuid1()), max_length=500, primary_key=True)    customername=models.CharField(max_length=1000,)我的表單.pyfrom .models import customerclass createcustomerform(ModelForm):    class Meta:        model=customer        fields=['customername']我的觀點(diǎn).pydef createcustomer(request):    if request.method=='GET':        return render (request,'marketing/createcustomer.html',{'form':createcustomerform()})    else:        try:            form=createcustomerform(request.POST)            newcreatecustomer=form.save(commit=False)            newcreatecustomer.user=request.user            newcreatecustomer.save()            return redirect('createcustomer')        except ValueError:            return render(request,'marketing/createcustomer.html',{'form':createcustomerform(),'error':'Check for Invalid Data. Try Again.'})我的html是<form method="POST">    {% csrf_token %}    <div id="customernamename"> <span>Company Name</span>      <input type="text" id="customername" placeholder="Enter Company's Full name"> </div></form>當(dāng)我單擊“保存”按鈕時(shí),它再次將我重定向到“createcustomer”,但不將數(shù)據(jù)保存在我的數(shù)據(jù)庫(kù)中。請(qǐng)幫助出什么問(wèn)題或我錯(cuò)過(guò)了什么?它通過(guò)管理區(qū)域而不是 html 頁(yè)面來(lái)保存客戶。
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個(gè)贊

你的錯(cuò)誤在這里:newcreatecustomer.user=request.user

變量newcreatecustomer沒(méi)有user字段;這就是它不起作用的原因。


查看完整回答
反對(duì) 回復(fù) 2023-07-11
  • 1 回答
  • 0 關(guān)注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)