【发布时间】:2013-12-02 15:40:56
【问题描述】:
我在 django 应用程序的views.py 中创建了一个类视图。
class HelloTemplate(TemplateView):
template_name = "index.html"
def get_context_data(self, **kwargs):
context = super(HelloTemplate, self).get_context_data(**kwargs)
return context
现在我在 html 页面中定义了一个表单:
<form method="get">
<input type="text" name="q">
<input type="text" name="q1">
<input type="submit" value="Search">
</form>
如您所见,我在同一页面上提交了form。
现在我想在HelloTemplate 类中获取表单提交的值。我不想在现有类之外创建另一个类或方法。
另外,如果数据未在 django 中验证,我想向 html 表单发送错误消息。
我不知道该怎么做,请帮帮我。
【问题讨论】:
标签: python html django django-forms