Django POST到其他视图

时间:2012-09-19 10:07:11

标签: django django-forms django-views

我有以下表单,该表单位于/

的网站根目录下
<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}}直接添加到播放视图中?

0 个答案:

没有答案