我的django项目有一个简单的页面
当按下“提交”时。 在我的视图.py如何捕获选定的单选按钮值和char字段的值
当提交时,相同的网页应该重新加载一个新的文本区域 该文本区域应该包含Radio selection+char字段连接的值
到目前为止,我已经创建了基本表单html视图。 我的主要问题是
在视图.py在
def index(request):
form=SfvForm()
if request.method == 'POST':
f = SfvForm(request.POST)
if f.is_valid():
form.result_text("hi")
return HttpResponseRedirect('index.html',{'posted':"posted"},{'form':form})
else:
return render_to_response("index.html",{"form":form} , context_instance = RequestContext(request))
else:
return render(request,'index.html',{'form':form})
在表单.py在
^{pr2}$在索引.html在
<!DOCTYPE html>
<html>
<head>
<title>SFV</title>
</head>
<body>
<h1> hello world!</h1>
<form id="form" method="post" action="/sfv/">
{% csrf_token %}
{{ form.as_p }}
</form>
<form id="form" method="get" action="/sfv/">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="submit"/>
</form>
</body>
</html>
我是因为当你重新定向时:
您需要使用您先前发布的
^{pr2}$form
值populate the new form相关问题 更多 >
编程相关推荐