![]() ![]() ( post_save, sender = User ) def update_user_profile ( sender, instance, created, ** kwargs ): if created : Profile. BooleanField ( default = False ) # other fields. OneToOneField ( User, on_delete = models. Models.py from django.db import models from import User from django.db.models.signals import post_save from django.dispatch import receiver class Profile ( models. If you want to configure a production quality email service, read more in this post:Ĭreate a field to determine if the email is confirmed or not: Settings.py EMAIL_BACKEND = '.console.EmailBackend' I have already published in great detail each one of those parts, so in this post I will just put the pieces together.įor testing purpose, I will be using the console email backend, to debug the code: Unique links with expiration date, and stuff like that. Because you know, you need to configure email, need some extra fields, This one requires a more complicated setup. The code is available on GitHub: /sibtc/simple-signup/tree/master/profile-model. Profile model, I would suggest creating two forms (say, UserForm and ProfileForm), and process both at once. I updated the birth_date directly in the view, but in case you are dealing with a bigger amount of fields in the Will trigger the profile save as well, that’s why you don’t need to call (), instead you call just If you don’t call user.refresh_from_db(), when you try to access the user.profile, it will return None.Īfter refreshing it user model, set the cleaned data to the fields that matter, and save the user model. This will cause a hard refresh from the database, which will retrieve the profile get ( 'password1' ) user = authenticate ( username = username, password = raw_password ) login ( request, user ) return redirect ( 'home' ) else : form = UserCreationForm () return render ( request, 'signup.html', )īecause of the Signal handling the Profile creation, we have a synchronism issue here. method = 'POST' : form = UserCreationForm ( request. Views.py from import login, authenticate from import UserCreationForm from django.shortcuts import render, redirect def signup ( request ): if request. Urls.py from import url from re import views as core_views urlpatterns = ![]() In case you are using the default Django user, using username to authenticate and is interested only in setting the The most simple way to implement a user sign up is by using the UserCreationForm as it is. So every time you see mysite and/or core, change to the suitable project name and app name.Ī brief summary of what you are going to find here: Inside the mysite folder I created an app You will see it’s very straightforward.įor the examples I will use an empty Django project named mysite. In this tutorial I will cover a few strategies to create Django user sign up/registration.
0 Comments
Leave a Reply. |