We can see on many websites how user registration is activated or enabled using email. That is, the user fills in the correct e-mail address after registration, and then the website sends an email message to the user setting, and provides an active or enabled link in the email, which is officially activated or enabled after the user clicks the link.
Here we use Django's Django-registration module to quickly implement this process.
1. django-registration Installation and Setup
To install using PIP:
Install django-registration
This module does not currently support Django2.0 or above, and it is recommended to use the following version of 2.0 for installation.
Add registration to the Installed_apps in the Django project Settings settings.py, and then set a constant in settings.py to specify the number of days for the enabler code.
installed_apps = ( " django.contrib.sites " " registration ", #should be immediately above " django.contrib.admin " '
Run Python manage.py migrate to install the model used by default settings. For the template to work correctly, the registration must appear above the django.contrib.admin.
Using a standard custom URL, add a line of settings to the url.py:
URL (r'^accounts/', include ('registration.backends.default.urls ')),
Any URLs assigned to/accounts/will be sent to registration to check if there are any items that match. The user can then register via/accounts/register/, login via/accounts/login/(when the user is registered) and so on.
2. Create the required templates for django-registration
When the user clicks the "Register" button, Django-registration will start to invoke a series of templates and related text files, which we need to write ourselves. All templates must be placed under the registration folder in the Templates directory.
Registration_form.html: Displays the page that registers the form, using the form variable as the content of the form's fields by default
Registration_complete.html: Fill out the Registration form, click the "Submit" button to display the information page
Activation_complete.html: The page that will be displayed when the account is successfully completed
Activate.html: page that appears when account activation fails
Activation_email.txt: Message content to use when sending mail-enabled
Activation_email_subject.txt: Message subject to use when sending mail-enabled
Note: Since Django-registration uses e-mail messaging, you should set up your Django e-mail and send and receive emails using Mailgun.
Related settings refer to my blog https://www.cnblogs.com/weixuqin/p/9263410.html.
At this point, we have completed the Djano-registration related settings, click on the registration, fill in the information, will be in the mailbox to receive the website verification email information.
Django implements Web site registration user Mailbox Verification function