我无法找到此错误。 在模型中添加了一个接触和可标记管理器的疾病中的一个字段后,出现错误 如果这是正确的,则由于我手动提供的Id字段而生成此错误 帮助我摆脱这个!!
个人(MYAPP)/urls.py
urlpatterns = [
url(r'^.*doctorsu/$', views.doctorsu.as_view(), name = 'doctorsu'),
url(r'^.*disease/$', views.AddDisease.as_view(), name = 'AddDisease'),
]
的mysite / urls.py
urlpatterns = [
url(r'^$',include('personal.urls')),
url(r'^taggit/',include('taggit_selectize.urls')),
]
models.py
class DoctorSignup(models.Model):
contact_regex = RegexValidator(regex=r'^[789]\d{9}$',message="Phone number must be start with 7,8 or 9")
doid = models.AutoField(verbose_name='Doctor Id',primary_key=True,default=0)
email = models.CharField(max_length=50)
contact = models.CharField(validators=[contact_regex])
class TaggedSymptoms(TaggedItemBase):
content_object = models.ForeignKey("Disease")
class TaggedMedicine(TaggedItemBase):
content_object = models.ForeignKey("Disease")
class Disease(models.Model):
did = models.AutoField(verbose_name='Disease Id', primary_key=True,default=0)
dName = models.CharField(max_length=20)
dtype = models.CharField(max_length=10)
symptoms = TaggableManager(through=TaggedSymptoms)
symptoms.rel.related_name = "+"
medi = TaggableManager(through=TaggedMedicine)
medi.rel.related_name = "+"
views.py
class doctorsu(TemplateView):
template_name = 'personal/doctorsu.html'
def get(self, request):
dsform = DoctorSignupForm()
data = DoctorSignup.objects.all()
args = {'dsform': dsform,'data': data}
return render(request,self.template_name,args)
def post(self, request):
dsform = DoctorSignupForm(request.POST)
if dsform.is_valid():
dsform.save()
cd = dsform.cleaned_data
args = {'dsform': dsform , 'cd': cd}
return render(request,self.template_name,args)
return render(request, 'personal/doctorsu.html')
class AddDisease(TemplateView):
template_name = 'personal/disease.html'
def get(self, request):
dform = DiseaseForm()
ddata = Disease.objects.all()
args = {'dform': dform,'ddata': ddata}
return render(request,self.template_name,args)
def post(self, request):
dform = DiseaseForm(request.POST)
if dform.is_valid():
dform.save()
cd = dform.cleaned_data
args = {'dform': dform , 'cd': cd}
return render(request,self.template_name,args)
forms.py
class DoctorSignupForm(forms.ModelForm):
dname = forms.CharField()
email = forms.EmailField()
contact = forms.RegexField(regex=r'^[789]\d{9}$',error_messages="Enter valid phone no.")
class Meta:
model = DoctorSignup
fields = "__all__"
class DiseaseForm(ModelForm):
dName = forms.CharField(help_text="Enter disease")
symptoms = TagField(help_text="Enter symptoms separated by comma")
medicine = TagField()
class Meta:
model = Disease
fields = "__all__"
回溯
追踪(最近一次呼叫最后一次):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
utility.execute()
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\base.py", line 327, in execute
self.check()
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\checks\urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\checks\urls.py", line 26, in check_resolver
return check_method()
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\urls\resolvers.py", line 254, in check
for pattern in self.url_patterns:
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\urls\resolvers.py", line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\urls\resolvers.py", line 398, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "E:\IT\project\program\20-8-17\mysite\mysite\urls.py", line 7, in <module>
url(r'^$',include('personal.urls')),
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\conf\urls\__init__.py", line 50, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "E:\IT\project\program\20-8-17\mysite\personal\urls.py", line 2, in <module>
from . import views
File "E:\IT\project\program\20-8-17\mysite\personal\views.py", line 3, in <module>
from personal.forms import *
File "E:\IT\project\program\20-8-17\mysite\personal\forms.py", line 50, in <module>
class DoctorSignupForm(forms.ModelForm):
File "E:\IT\project\program\20-8-17\mysite\personal\forms.py", line 90, in DoctorSignupForm
contact = forms.RegexField(regex=r'^[789]\d{9}$',error_messages="Enter valid phone no.")
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\forms\fields.py", line 517, in __init__
super(RegexField, self).__init__(max_length, min_length, *args, **kwargs)
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\forms\fields.py", line 228, in __init__
super(CharField, self).__init__(*args, **kwargs)
File "C:\Users\Charmi Shah\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\forms\fields.py", line 122, in __init__
messages.update(error_messages or {})
ValueError: dictionary update sequence element #0 has length 1; 2 is required