Django realizes registration and login (with source code)

Table of contents

1. Project introduction

1. Development environment

2. Introduction of registration function

3. Introduction to login function:

4. Screenshot of the project

 2. Data Migration

1. Create your own database

(1) Enter your own database through the command line (win+R, enter cmd), as shown in the figure below, it means that the entry is successful

 (2) Create your own database

(3) Configuration database

 (4) Create a migration file

(5) Perform data migration

 (6) Run the project

 (7) Enter the page

3. Project effect display

1. Home page

(2) Login page

(3) Registration page

(4) Home page after login

 4. Source code

5. Matters needing attention

6. Expectations


1. Project introduction

1. Development environment

Development tools: PyCharm 2021

Database: MySQL 8.0

Database management software: Navicat 15.0.27

Development framework: Django

2. Introduction of registration function

        When registering an account for this project, the user name is set as the primary key, and the password will be encrypted during registration and cannot be decrypted, which means that if the password is forgotten, it cannot be modified through the database. If the registered user names are the same, the registration will fail and you need to re-register.

3. Introduction to login function:

        When logging in to this project, if the password is incorrect, it will prompt that the password is wrong, and you need to return to the login page to log in again; if the user name has not been registered, it will prompt that the user name does not exist, and you need to return to the login page to log in again or register the user name directly.

4. Screenshot of the project

 2. Data Migration

1. Create your own database

(1) Enter your own database through the command line (win+R, enter cmd), as shown in the figure below, it means that the entry is successful

 (2) Create your own database

        The login in the above picture is the name of the database I created, enter "show databases;" to view all our databases.

(3) Configuration database

        In the settings.py file of our project, configure the database as shown in the figure below to prepare for our data migration.

 (4) Create a migration file

        Enter the following line of code on the control command line:

python manage.py makemigrations

         The result shown in the above figure means that the creation of the migration file is successful, and there will be an additional file named 0001_initial.py in the migrations folder of the project.

(5) Perform data migration

                Enter the following line of code on the control command line:

python manage.py migrate

         The result as shown in the figure below means the migration was successful. At this time, we can find in the database that we have created 11 tables, the first 10 are automatically created by the system, and the eleventh table user is a table created by ourselves. As shown below:

 (6) Run the project

        Enter the following line of code, and the successful operation will be as shown in the figure below:

python manage.py runserver

 (7) Enter the page

        At this point, we copy http://127.0.0.1:8000/ to any browser, and then enter user/index (user/login or user/register is fine) to jump to our page.

3. Project effect display

1. Home page

 

(2) Login page

(3) Registration page

(4) Home page after login

 4. Source code

Link: https://pan.baidu.com/s/15CV1pYgZq3jdn-S3YNzBUg?pwd=rb4j 
Extraction code: rb4j 

5. Matters needing attention

        The style layout in this project is the end-of-course homework I did when I was in the sophomore front-end class. At that time, I borrowed a code from a blogger. Although I collected it at the time, I couldn’t find it later.

        Since the project was completed by myself based on what I have learned, the code in the style section is a bit messy, and some may be invalid, but I am too lazy to change it, because the first is that it does not affect the operation of the project, and the second is that What a blogger wrote is really great, and if I change it with my ability, it will probably destroy its original beauty.

        This project is only for your reference and study, not for commercial use!

        If there is any infringement, please contact me to delete it in time! ! !

6. Expectations

        I'm posting here for nothing, partly because of the teachers, friends, and even random strangers I've met who have always offered me a helping hand when I was in trouble, without asking for anything in return. Therefore, I hope that this article of mine can also help those in need and pass on the love. On the other hand, the so-called "teaching benefits each other", I can deepen my impression and consolidate the knowledge I have learned while helping others.

        I wish you all a happy body and mind, smooth work and successful career!

        Looking forward to your likes and collections!

        

Guess you like

Origin blog.csdn.net/weixin_51756038/article/details/130903584