我有以下表单,该表单位于/
<form action='/play/' method='post'>
{% csrf_token %}
{{ form.player_name }}
<input id='play' type='submit' value='Play'>
</form>
然后我有了验证这种形式的观点:
def login(request):
context = {}
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
return HttpResponseRedirect('/play/')
else:
context.update(dict(form=form))
else:
context.update(dict(form=LoginForm(initial={'player_name':'Please tell us your name'})))
return render_to_response('login.html', context, context_instance=RequestContext(request))
实际播放视图:
def play(request):
p1 = briscola.Player(request.POST['player_name'])
问题是当然重定向会丢失POST
数据。但是,当POST
?
form.is_valid
直接将{{1}}直接添加到播放视图中?