如何访问 django 扩展平面页面中的字段?
我写了这个:
class ExtendedFlatPage(FlatPage):
teaser = CharField(max_length=150)
class ExtendedFlatPageForm(FlatpageForm):
teaser = CharField(max_length=150)
class Meta:
model = ExtendedFlatPage
class ExtendedFlatPageAdmin(FlatPageAdmin):
form = ExtendedFlatPageForm
fieldsets = (
(None, {'fields': ('url', 'title', 'teaser', 'content', 'sites',)}),
)
admin.site.unregister(FlatPage)
admin.site.register(ExtendedFlatPage, ExtendedFlatPageAdmin)
在管理员中创建是可以的。但后来在 flatpages/default.html 我尝试了这个:
<html>
<body>
<h1>{{ flatpage.title }}</h1>
<strong>{{ flatpage.teaser }}</strong>
<p>{{ flatpage.content }}</p>
</body>
</html>
而且没有 flatpage.teaser!怎么了?