It took a god-level programmer fifteen days to summarize "Flask Web Development"


Original title: It took a god-level programmer fifteen days to summarize "Flask Web Development"! The most complete tutorial ever


The solution is as follows:

The solution is shown below:

2. There is a bug in inserting new user data with shell on page 87 of the book

The problem is that the database design contains foreign keys, and the code is inserted directly according to the book, without inserting the user role foreign key, it is impossible to insert data.

Solution: delete the many-to-one relationship between the User table and the Role table

Then, delete all **.sqlite files and migrations folders in the project as follows:

Then follow the three steps shown in the figure below to recreate the database (PS: see Chapter 5, Section 5.11 for the method here):

After these processing are completed, insert the code according to the book, and still report the error of User and db not found, the solution is as follows:

After completing the above data insertion tasks, enter python manage.py runserver in the CMD console to start the service, enter http://127.0.0.1:5000/auth/login in the browser, and then log in with the inserted mailbox number and password. Got the following result:

4. The book page 92 performs a new database migration

In the CMD window, enter the python manage.py db migrate -m "the second migration" and python manage.py db upgrade commands in turn. The specific execution and results are as follows:

5. The code of example 8-22 on page 94 of the book has the bug shown in the figure below because of the Flask-Login version problem

The solution is shown below:

What confuses me is that I was looking at the physical book when I wrote the notes. There is a problem with the code above. The screenshot below is an e-book, but the above is correct >~<, as follows:

Problem solution URL (https://segmentfault.com/q/1010000004041497)

Test the is_authenticated method as follows:

Additional book 95 page running results:

Note: Chapter 8 mainly explains how to use the Flask framework to implement user login and registration functions, as well as use email for user registration confirmation and password modification confirmation. I feel that the content of Chapter 8 is a comprehensive exercise of the content of the first 7 chapters of the book, and all the technical points used can be found in the first 7 chapters. Therefore, I personally feel that as long as you understand all the code and implementation ideas in Chapter 8, you are just getting started with the Flask framework.

Well, since there is a one-to-many foreign key relationship between the Role table and the User table, when the registration function inserts user data, the user role must be confirmed, otherwise it cannot be inserted.

The registration test has just been conducted, and the user role can be successfully inserted without determining the user role. This feeling goes against my theoretical knowledge of learning databases. In Chapter 5, when inserting data, it doesn't work, and now it's okay. It is estimated that the code was a bit buggy when learning before.

Note: This chapter is equivalent to mainly talking about database knowledge, and has little to do with the knowledge points of the core Flask framework in this book. The core idea is to define permissions to assign role levels. A user may have only one permission, and some may have multiple permissions. The distribution of permissions is very flexible, which greatly simplifies the design difficulty of the database and improves the organization of the data.

Admin modify personal information interface

Profile page showing user avatar

Note: This chapter mainly implements the personal information editing function of the ordinary user and administrator roles of the blog system. There are no technical highlights and difficulties in the implementation here. As long as the aforementioned parts of the book are carefully completed, this part of the function is completely free of obstacles.

Chapter 11 Blog Posts

1. Example 11-8 code on page 119 of the book

This part of the code has no sample code on the author's GitHub, that is, if you want to implement the function of importing virtual data for testing, you can only type one code at a time. However, this is too much. If a letter is wrong, it must be corrected >~<. The code directly cloned from the author's GitHub, although there is no sample code, it should be another implementation method after the author updated the code, because a new fake.py file appears in the project file, the The code in the file is basically similar to the code in Example 11-8.

Note: This chapter is an extension of the functions of the blog system. It mainly realizes that users can edit and send blog articles. You can also use MarkDown to edit articles. The specific implementation of the function can be explained by referring to the code in the book, and basically there will be no difficult problems.

Chapter 12 Followers

1. The actual running results of the 137 pages and 142 pages of the book

Note: The difficulty of the specific implementation part of this chapter is to focus on the design of the database table of user records, that is, a multi-pair relationship will generate an intermediate table. Other parts, according to the code in the book to operate on the computer, basically will not encounter any difficulties.

Chapter 13 User Reviews

1. The 148 pages and 151 pages of the book actually run the results of the machine

Note: This chapter mainly implements the user comment function of the blog, and adds a coordinator permission. There is no difficulty in the specific implementation, just follow the code in the book to operate on the computer.

http://www.sohu.com/a/216839756_100033985

Guess you like

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