def save(request): if request.method == 'POST': user_form = UserForm(request.POST) profile_form = UserProfileInfoForm(request.POST) if profile_form.is_valid() and user_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if 'profile_pic' in request.FILES: profile.profile_pic = request['profile_pic'] profile.save() return render(request, 'form_app/save.html')
def form_view(request): fo = UserForm() if request.method == "POST": fo = UserForm(request.POST) if fo.is_valid(): print("Name: " + fo.cleaned_data['name']) fo.save() return render(request, 'form_app/fill.html', context={'form': fo})
def register(request): registered=False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserInfoForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if 'profile_pic' in request.FILES: profile.profile_pic = request.FILES['profile_pic'] profile.save() registered=True else: print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = UserInfoForm() return render(request,'form_app/registration.html',{'user_form':user_form,'profile_form':profile_form,'registered':registered})
def user_signup_view(request): registered = False if request.method == 'POST': user_form = UserForm(data = request.POST) info_form = UserInfoForm(data = request.POST) if user_form.is_valid() and info_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() info = info_form.save(commit = False) info.user = user if 'profile_pic' in request.FILES: info.profile_pic = request.FILES['profile_pic'] info.save() registered = True return render(request, 'form_app/thankyou.html') else: print(user_form.errors,info_form.errors) else: user_form = UserForm() info_form = UserInfoForm() return render(request, 'form_app/signup.html', {'user_form':user_form, 'info_form':info_form, 'registered':registered})
def formpage(request): #return HttpResponse("<em>from Form Page</em>") form = UserForm() if request.method == 'POST': form = UserForm(request.POST) if form.is_valid(): form.save(commit=True) #print("Validation Success!") #print("Name: " + form.cleaned_data['first_name']) return render(request, 'form_app/form_page.html', {'form': form})
def register(request): profile_form = UserProfileInfoForm() user_form = UserForm() context = {'profile_form': profile_form, 'user_form': user_form} return render(request, 'form_app/register.html', context)