Today's Contents:
1. The table design library management system
2.django request lifecycle
3. routing layer
4. View layer
A. Establish relationships between tables and tables
Take this book management system as an example: books table Press table of table books and publishers are many, the foreign key field built in the books table books and authors is many to many, the need to record more than a third of the table multi relationship to build relationships between django orm tables table 1 . many foreign key relationship publish = models.ForeignKey (to = ' publish ' ) # to represent what is now the default-to-many relationship tables are is established with the primary key field of the table relationship 2 . many relationship authors = models.ManyToManyField (to = ' Author ' ) # does not generate authors field the field is a virtual field in the table is only used to tell django orm automatically help you create books and the author of the third table 3 . one relationship author_detail = models.OneToOneField (to = ' AuthorDetail ' ) Note! ! ! ! : 1 . One-to-many and will automatically add another field behind _id. 2. However, many to many, will not have a real field, just tell django orm automatically create a third table
Two .django request lifecycle
III. Routing layer
URL () method of the first parameter which is a regular expression URL (R & lt ' ^ ADMIN ' , admin.site.urls), URL (R & lt ' ^ adminqwe ' , views.login), not slash, then, Once in front of the regular expression matching to the content, we will not continue down the match, but the implementation of the corresponding view function directly ps: due to the above characteristics official, when your project is particularly large when, url before and after the order is you need to consider the situation may arise url disorder
url (r '^ login / $', views.login) wrote words that begin with the end in what what are generally written