【发布时间】:2011-12-12 04:53:51
【问题描述】:
我正在显示一个 django 表单,我想在它之前准备一些字段数据 被传递给被渲染。在 django 文档中,我看到很多地方 访问表单数据的位置,但没有在显示之前设置表单数据的位置。
关于如何做到这一点有什么想法或建议吗?
这是一个类似于 django 文档的示例。
-----------forms.py--------------
class BookForm(ModelForm):
author = forms.CharField(max_length=100)
title = forms.CharField(max_length=3,
widget=forms.Select(choices=TITLE_CHOICES))
birth_date = forms.DateField(required=False)
-----------views.py--------------
def author_view(request):
if request.method == 'POST':
# DO My processing...
form = BookForm()
# How can I edit, or preset my form fields here?
c = Context({
'form': form,
})
return prepCxt(request, 'book.html', c) # Wrapper for easy display
【问题讨论】: