Write your own blog with flask (2)

This article briefly explains the file structure of the blog project
app ---> program main directory
api--> api
auth in the test --> login authentication file
main--> main entry file
static--> static file
template--> HTML template file
migrations-->SQLAlchemy generated file for data migration
test-->selenuim test file

Write your own blog with flask (2)

Create flask instance:

Write your own blog with flask (2)
Load third-party plugins that need to be loaded, such as csrf, bootstrap


Set blueprint in app.init to register all pages

Write your own blog with flask (2)

The static_folder points to the static directory under the app, which is referenced by url_for() in the page

auth blueprint creation (same as main blueprint)

Write your own blog with flask (2)
Contains all the modules in the auth package (forms and attempts)
Write your own blog with flask (2)
Some background functions needed to write pages in views
Write your own blog with flask (2)

1. Use the current_user in flask_login to judge whether the user is logged in (the logged-in current_user contains the user ID, use the hasattr function to judge, and jump to the specified page)

2. form.validate_on_submit judges whether the user submits the form (you can also use the post in methods to judge)

3. Log in to the authentication process, and return different flash messages according to the situation. If the authentication is successful, jump to the specified page.

selenium unit testing

The Chrome browser is called for testing, Chromedriver.exe is required, and Baidu is downloaded by itself (the picture below is a gif animation, it seems that it cannot be used- )

Write your own blog with flask (2)
Write your own blog with flask (2)

The code in the views module is similar, only one is listed, and some functions will be explained separately later

The third bullet: analyze the jinja2 web page template and use bootstrap+wtf to quickly layout (to be continued)

The fourth bullet, the summary of the entire project and the introduction of extensions, qrcode and other gadgets (...)

Write your own blog with flask (1)
Project source address: Github

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324650881&siteId=291194637