在Django我試圖爲ContactForm編寫一個ModelForm,當我嘗試加載包含表單的頁面時,它不存在。然後,當我試圖使我以前寫它說,模型在models.py中一起出血?
Caught AttributeError while rendering: 'CashtextsForm' object has no attribute 'subject'
「主題」的格式爲一個領域,我試圖在ContactForm的一個來渲染其他形式。那麼是否有一些特定的命令我必須在models.py中列出它們?下面是代碼:
# Create your models here.
from django.db import models
from django.forms import ModelForm
class Cashtexts(models.Model):
cashTexts = models.CharField(max_length=100, blank=True) #change me to a website filter
superPoints = models.CharField(max_length=100, blank=True)#chance to "superPoints _Username"
varolo = models.CharField(max_length=100, blank=True)
swagbucks = models.CharField(max_length=100, blank=True)
neobux = models.CharField(max_length=100, blank=True)
topline = models.CharField(max_length=100, blank=True)
Paidviewpoint = models.CharField(max_length=100, blank=True)
cashcrate = models.CharField(max_length=100, blank=True)
def __unicode__(self):
return self.cashcode
class Contact(models.Model):
sender = models.EmailField()
subject = models.CharField(max_length=25)
message = models.TextField()
class CashtextsForm(ModelForm):
class Meta:
model = Cashtexts
def __unicode__(self):
return self.subject
class ContactForm(ModelForm):
class Meta:
model = Contact
我以前他們安排爲模型的ModelForm,模型的ModelForm但here這表明他們像我現在目前有他們的方式。
也有沒有任何優勢,只寫表格?現在我更喜歡在表單上編寫模型表單(我不認爲它們有很大不同),但是如果我只寫了模型表單,我會錯過哪些功能?那麼,我有沒有想過如何在models.py中編寫多個表單,或者我有沒有寫過worng?或者我可以不通過命令syncdb創建它們?
好吧我改變了這一點,現在CashtextsForm的作品,但它仍然說聯繫表格不存在。任何想法爲什麼它不被創建? – city 2012-04-13 15:32:58
你現在收到了什麼確切的錯誤信息? – cfedermann 2012-04-13 15:36:56
NameError at/contact/ 全局名稱'ContactForm'未定義 – city 2012-04-13 15:51:24