def register(request): registered = False if request.method == 'POST': user_form = UserForms(data=request.POST) profile_form = UserProfileInfoForm(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 profile.save() registered=True else: print(user_form.errors, profile_form.errors) return render(request, 'app1/registration.html', {"forms": UserForms, "profile_form": UserProfileInfoForm,"registered":registered})
def register(request): registered=False if request.method== "POST": user_form=UserForm(data=request.POST) profile_form=UserProfileInfoForm(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=UserProfileInfoForm() print(registered) return render(request,'registration.html', {'user_form':user_form,'profile_form':profile_form,'registered':registered})
def signup_view(request): registered = False if request.method == 'POST': user_form = Userform(data=request.POST) profile_form = UserProfileInfoForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): print("Validated") user = user_form.save() user.set_password(user.password) # lecture 152 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 return index(request) else: print(user_form.errors, profile_form.errors) else: user_form = Userform() profile_form = UserProfileInfoForm() return render( request, 'signup.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def register(request): registered = False error_s = "" if (request.method == 'POST'): user_form = UserForm(data=request.POST) profile_form = UserProfileInfoForm(data=request.POST) if (user_form.is_valid() and profile_form.is_valid()): user = user_form.save(commit=False) user.set_password(user.password) user.username = user.email user.save() profile = profile_form.save(commit=False) profile.user = user # Check if they provided a profile picture if 'profile_pic' in request.FILES: print('found it') # If yes, then grab it from the POST form reply profile.profile_pic = request.FILES['profile_pic'] # Now save model profile.save() registered = True else: print(user_form.errors, profile_form.errors) error_s1 = str(user_form.errors) error_s2 = str(profile_form.errors) user_form = UserForm() return render( request, 'app1/registration.html', { 'error_s1': error_s1, 'error_s2': error_s2, 'user_form': user_form, 'profile_form': profile_form }) else: user_form = UserForm() profile_form = UserProfileInfoForm() return render( request, 'app1/registration.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileInfoForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() # commit=False -> not yet submited to db profile = profile_form.save(commit=False) # get the user 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 = UserProfileInfoForm() return render(request, 'app1/register.html', context={ 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def register(request): registered = False if request.method == "POST": user_form = UserProfileForm(request.POST) prof_form = UserProfileInfoForm(request.POST) if user_form.is_valid() and prof_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() # profile has 1:1 with user. tag the user profile = prof_form.save(commit=False) profile.user = user if "picture" in request.FILES: profile.picture = request.FILES['picture'] profile.save() registered = True else: # forms aren't valid print(user_form.errors, prof_form.errors) else: # No POST -- render base form user_form = UserProfileForm() prof_form = UserProfileInfoForm() data = { 'registered': registered, 'user_form': user_form, 'profile_form': prof_form } return render(request, "app1/registration.html", context=data)