[Answer]-Multiple forms in a template

1👍

from django.template import RequestContext
from django.shortcuts import render_to_response
from .forms import AForm, BForm, CForm

def some_view(request):
    if request.method == 'POST':
        a_form = AForm(request.POST, request.FILES)
        b_form = BForm(request.POST, request.FILES)
        c_form = CForm(request.POST, request.FILES)

        if a_form.is_valid():
            #do stuff...
        if b_form.is_valid():
            #do stuff...
        if c_form.is_valid():
            #do_stuff...
    else:
        a_form = AForm()
        b_form = BForm()
        c_form = CForm()
    variables = RequestContext(request, {'a_form': a_form, 'b_form': b_form, 'c_form': c_form})
    return render_to_response('page.html', variables)
👤msc

Leave a comment