对ModelForm
使用form_class
作为UpdateView
时,我遇到了一个奇怪的问题。
首先:使用不带UpdateView
标记的form_class
时,一切都运行正常。但是,当我尝试使用ModelForm
时(因为我想添加MarkdownField),我在浏览器窗口中显示<mediwiki.views.MediwikiForm object at 0x7f990dfce080>
。只是用纯文本?
#template/mediwiki/create2.html:
<form action="" method="post">{% csrf_token %}
{{ form }}
<input type="submit" value="Save" />
</form>
#views.py:
class EntryUpdate(UpdateView):
model = Mediwiki
slug_field = 'non_proprietary_name'
template_name = "mediwiki/create2.html"
form_class = MediwikiForm⋅
#fields = '__all__' #this works...
#forms.py
class MediwikiForm(ModelForm):
# wiki_page_markdown = MarkdownxFormField()
class Meta:
model = Mediwiki⋅
fields = ['non_proprietary_name', 'category', 'wiki_page_markdown']
#models.py
class Mediwiki(models.Model):
non_proprietary_name = models.CharField(max_length = 100, unique = True)
category = models.ManyToManyField(Category)
wiki_page = models.TextField(blank = True)
wiki_page_markdown = models.TextField(blank = True)
def save(self):
import markdown
self.wiki_page = markdown.markdown(self.wiki_page_markdown)
super(Mediwiki, self).save() # Call the "real" save() method.
def get_absolute_url(self): # For redirect after UpdateView
return reverse('entry', kwargs={'slug': self.non_proprietary_name})
def __str__(self):
return self.non_proprietary_name
#urls.py
url(r'^mediwiki/(?P<slug>\D+)/edit$', EntryUpdate.as_view(), name="update"),
知道什么可能导致此错误吗?任何帮助将不胜感激......