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
Create flask instance:
Load third-party plugins that need to be loaded, such as csrf, bootstrap
Set blueprint in app.init to register all pages
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)
Contains all the modules in the auth package (forms and attempts)
Some background functions needed to write pages in views
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- )
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