我想要一個視圖,可以在我創建的模型「聯繫人」中添加新聯繫人。 下面是一些代碼行被關注NameError:未定義名稱''
views.py:
def contact(request):
form = ContactForm(request.POST or None)
if form.is_valid():
sujet = form.cleaned_data['sujet']
message = form.cleaned_data['message']
envoyeur = form.cleaned_data['envoyeur']
renvoi = form.cleaned_data['renvoi']
envoi = True
return render(request, 'blog/contact.html', locals())
def nouveau_contact(request):
sauvegarde = False
form = NouveauContactForm(request.POST or None, request.FILES)
if form.is_valid():
contact = Contact()
contact.nom = form.cleaned_data["nom"]
contact.adresse = form.cleaned_data["adresse"]
contact.photo = form.cleaned_data["photo"]
contact.save()
sauvegarde = True
return render(request, 'blog/newcontact.html', {
'form': form,
'sauvegarde': sauvegarde
})
forms.py:
class ContactForm(forms.Form):
sujet = forms.CharField(max_length=100)
message = forms.CharField(widget=forms.Textarea)
envoyeur = forms.EmailField(label="Votre adresse mail")
class NouveauContactForm(forms.Form):
nom = forms.CharField()
adresse = forms.CharField(widget=forms.Textarea)
photo = forms.ImageField()
class Contact(models.Model):
nom = models.CharField(max_length=255)
adresse = models.TextField()
photo = models.ImageField(upload_to="photos/")
def __str__(self):
return self.nom
錯誤消息告訴我「」NewContactForm「」未定義 this is the ERROR_MESSAGE
您忘記了導入 – e4c5
不同的文件如何關聯?哪個文件給出錯誤信息?進口產品是什麼樣的? – acdr
明白了,thanx很多 –