def index(request): form = userForm() if request.method == 'POST': form = userForm(request.POST, request.FILES) if form.is_valid(): form.save() return HttpResponse( "<h1 style='color:green'>Data Saved Successfully</h1>") return render(request, 'myapp/upload.html', {'form': form})
def add(request): if request.method == "POST": form = userForm(request.POST) if form.is_valid(): try: form.save() return redirect('/home') except Exception as e: return HttpResponse("Exception: " + str(e)) else: return HttpResponse("Invalid Data:" + str(form.errors.as_data())) else: form = userForm() return render(request, 'add.html', {'form': form})
def edit_save(request, id): user_list = user.objects.get(id=id) form = userForm(request.POST, instance=user_list) if form.is_valid(): try: form.save() return redirect("/home") except Exception as e: return HttpResponse("Exception: " + str(e)) else: return HttpResponse("Invalid Data:" + str(form.errors.as_data())) return render(request, 'edit.html', {'user': user_list})