Django website combat-hand in hand with everyone to make a classic website

Click on " Python crawler and data mining " above to follow

Reply to " Books " to receive a total of 10 e-books of Python from beginner to advanced

now

day

Chickens

soup

Don't dream of Yiyi's arrival at Xie's house, the Xiaolang round turns slanting.

I. Introduction

Today, the editor takes you to make a classic website case. The functions include login, registration, logout, password change, password-free login, and forgot password, so let's start below.

Two, create a project and create sub-applications

First create the project, and then create the sub-application in the project root directory, as follows:

django-admin startproject demo #创建项目
python manage.py startapp web  #创建子应用

Three, configuration

Enter the project directory and open settings.py to make the corresponding settings, as follows:

The configuration of the mail client here requires the use of an authorization code, which is solved by Baidu for details.

Three, configure the urls file

First, we need to configure the urls file of the project, as shown in the figure:

Then there is the urls file of the application. By default, the urls file of the application does not exist. We need to create a new urls.py file and write the content in it. As for the content, it is actually the introduction of the routing function we wrote in the view file. , We first write all routing functions in, as shown in the figure:

Fourth, create a model

Because we are doing a website and we have login and registration functions, we need to have a user, password, and email. First, write the content in the models.py file in the web application, as shown in the figure:

Five, form

Then we also need to write a form for user input, as shown in the figure:

Six, the preparation of the view function

If you want the website to run successfully, you must have the support of the view function, as shown in the figure:

Seven, the preparation of the front-end page

If you want the backend to process the front-end data, then the front-end page must also be written. Django and Flask provide a complete set of mvt design patterns, which greatly reduces the front-end code and ensures security.

Eight, create a database migration

This step is very important. If you use database storage and you do not create a migration, then the project will go wrong. Generally, two steps are ok, as follows:

python manage.py makemigrations  # 创建数据库迁移文件
python manage.py migrate  # 根据数据库迁移文件生成对应SQL语句并执行

Please be sure to follow the order given by the editor for the initial creation.

Nine, start the project

CMD enters the command to start the project, as shown in the figure:

Then we take a look at the final effect, as shown in the figure:

Note: There are still many functions that I haven't demonstrated one by one, mainly because it takes too much effort to capture the demo screen gif, but the functions are relatively complete, although the code is not so beautiful.

Since the GIF image exceeds 300 frames and cannot be uploaded to the background, everyone can't see the complete animation. The editor put the dynamic image here on Github.

https://github.com/cassieeric/python_crawler/tree/master/DjangoWebDevelopAutoLogin

10. Summary

A django website written in this article can be said to be a relatively satisfactory work for the editor, with relatively complete functions, although the interface is not well done.

Friends who need the project code of this article, please reply to the keyword " website development actual combat " in the backstage of the official account to obtain it. If you encounter any problems during the operation, please feel free to leave a message. The editor will help you solve the bug if you see it!

------------------- End -------------------

Recommendations of previous wonderful articles:

Welcome everyone to like , leave a message, forward, reprint, thank you for your company and support

If you want to join the Python learning group, please reply in the background [ Enter the group ]

Thousands of rivers and mountains are always in love, can you click [ Looking ]

/Today's message topic/

Just say a word or two~~

Guess you like

Origin blog.csdn.net/pdcfighting/article/details/113706178