[Django]-Render two views to a single html template

4👍

Not possible to render two different views to the same template, but you can add both the logics in a single view and then render both forms in that:

from django.shortcuts import render
from django.http import HttpResponse
from app.models import *

def institute_view(request):

    f = schoolform(requst.POST or None)
    form = collegeform(requst.POST or None)
    if request.method == 'POST':
        if form.is_valid():
            form.save()
            return HttpResponse('its done here')
        elif f.is_valid():
            f.save()
            return HttpResponse('its done here')
        else:
            f = schoolform()
            form = collegeform()

    return render(request, 'about.html', {'f':f,'form':form})

By this method, both of your forms can be handled and whenever anyone of them gets posted the values will be saved accordingly.

Leave a comment