[Answered ]-Form is not rendered in the template after redirection (django)

2👍

You should pass the form instance to your template as you do in index view. Your code shall be updated to

def modelUpdate(request):
    if 'update' in request.POST: # If the form has been submitted...
        form_class = get_dynamic_form(request.GET['model_classes_field']) 
        form = form_class(request.POST)         
        if form.is_valid(): # All validation rules pass
            row = form.save() #saves into database 
            #------------------------------------------------v pass it to template
            return render(request, 'Directories/index.html', {'form': form})
        else:
            print "form errors: ", form.errors
            return HttpResponse('ERROR -- Return to form submission')
👤Rohan

Leave a comment