防止表单字段显示在浏览器中

时间:2013-06-14 12:55:06

标签: python html django

我有一个表单,并希望不显示用户字段。

models.py

class Questions(models.Model):
    user=models.ForeignKey(User)
    category=models.ForeignKey(Categories)
    question=models.TextField(max_length=500)
    created_date=models.DateTimeField('date created')
    def __unicode__(self):
        return "%s%s" %(self.question,self.created_date)

class QuestionsForm(ModelForm):
        class Meta:
            model = Questions
        widgets = {
            'question': TextInput(attrs={'placeholder': 'Add question here'})
        }
        exclude=('user',)

我尝试排除,但该字段仍然显示。怎么做??

1 个答案:

答案 0 :(得分:3)

注意你的缩进:

class QuestionsForm(ModelForm):
    class Meta:
        model = Questions
        widgets = {
            'question': TextInput(attrs={'placeholder': 'Add question here'})
        }
        exclude=('user',)