2

我有以下形式存在于站点根目录中/

<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呢?

4

0 回答 0