def student_form(request): form = forms.StudentForm() if request.method == "POST": form = forms.StudentForm(request.POST) if form.is_valid(): form.save(commit=True) return index(request) diction = {'title': "student_form", "student_form":form} return render(request, 'first_app/student_form.html', context=diction)
def student_update(request, student_id): student_info = Student.objects.get(pk=student_id) form = forms.StudentForm(instance=student_info) if request.method == "POST": form = forms.StudentForm(request.POST, instance=student_info) if form.is_valid(): form.save(commit=True) return index(request) diction = {'student_form': form} return render(request, 'first_app/student_update.html', context=diction)
def Student_Form(request): form = forms.StudentForm() if request.method == "POST": form = forms.StudentForm(request.POST) if form.is_valid(): form.save(commit=True) return redirect("first_app:index") context = { 'Title': "Student Form", "student_form": form, } return render(request, 'student_form.html', context=context)
def StudentUpdate(request, student_id): student_info = Student.objects.get(pk=student_id) form = forms.StudentForm(instance=student_info) if request.method == "POST": form = forms.StudentForm(request.POST, instance=student_info) if form.is_valid(): form.save(commit=True) return redirect("first_app:index") context = { 'Title': "Student Update", 'student_form': form, } return render(request, 'student_update.html', context=context)