Skip to content Skip to sidebar Skip to footer

Django Form Not Saving Inputs- Refreshes Upon Submission

I am trying to create a website with two dropdown menus: Department and Course Number. The data for the dropdown menus comes from the 'courses' table of my SQL database. Right now

Solution 1:

def home(request):
    context = {}
    res = None
    if request.method == 'POST':
        form_CourseForm = CourseForm(request.POST)
        working_info = Working_Form(request.POST)
        args = {}
        if form_CourseForm.is_valid():
            if request.POST['dept']:
                args['dept'] = request.POST['dept']
            if request.POST['course_num']:
                args['course_num'] = request.POST['course_num']
        if working_info.is_valid():
            ...

        if ('dept' in args) == ('course_num' in args): 
            try:
                results = process_inputs(args)
            except Exception as e:
                print('Exception caught')
        else:
            context['err'] = forms.ValidationError("Error")
            results = None
        return render(request,'template.html',{'args':args})
    else:
        form_CourseForm = CourseForm()
        working_info = Working_Form()

and also in html

<form method='post' action='' ...... >

Post a Comment for "Django Form Not Saving Inputs- Refreshes Upon Submission"