gpt4 book ai didi

python - ModelForm 没有属性 get

转载 作者:太空宇宙 更新时间:2023-11-04 10:19:11 25 4
gpt4 key购买 nike

我在 Django 1.8 项目中收到 ModelForm has no attribute 'get' 错误。我读过关于该主题的类似问题,但我还没有找到任何解决方案:

django 'User' object has no attribute 'get' error

object has no attribute 'get'

访问 url: patients/add 时出现上述错误:

代码如下:

表单.py

class addPatient(forms.ModelForm):
class Meta:
model = PatientUser
fields = ['gender']

views.py

  def add_patient(request):
if request.method == "GET":
form = addPatient(data=request.POST)
if form.is_valid():
new_user = Patient.objects.create_user(**form.cleaned_data)
# login(new_user)
# redirect, or however you want to get to the main view
return HttpResponseRedirect('base.html')
else:
form = addPatient()

return render(request, 'addpatient.html', {'form':form})

模型.py

class PatientUser(models.Model):
children_quantity = models.CharField(max_length=1,
choices=CHILDREN_QUANTITY_CHOICES, default=CERO)
merried_lastname = models.CharField(max_length=175, blank=True)
date_of_birth = models.DateField(null=True)
citenzenship = models.CharField(max_length=175, blank=True)

urls.py

from django.conf.urls import include, url, patterns
from django.contrib import admin
from django.conf import settings
from . import views

admin.autodiscover()

urlpatterns = (
url(r'^$', views.records_general, name="records_general"),
url(r'^search/$', views.records_search, name="records_search"),
url(r'^single/(?P<id>\d+)/$', views.records_single, name="records_single"),
url(r'^add/$', views.addPatient, name="addPatient"),

)

谁能帮我找出代码中的问题?

谢谢。

最佳答案

您已将您的 URL 指向 addPatient,但这就是表单。 View 是 add_patient

关于python - ModelForm 没有属性 get,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33445812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com