Django-Component Supplements

Knowledge preview

A Django form component

Two Django's model form components

Three Django caching mechanism

Four Django Signals

Five Django serialization

A Django form component

forms component

Two Django's model form components

This is a magical component. We can see from the name that the function of this component is to combine model and form. Let's take a simple example to see how to use this thing: for example, there is such a student in our database. Table, fields include name, age, hobby, email, phone, address, registration time and a lot of information, now let you write a page for creating students, how should you write in the background? First, we will list these fields one by one on the front end for the user to fill in, and then we will receive the user's input one by one from the day after tomorrow, create a new student object, and save it. In fact, the focus is not on these, but on legality verification. It is necessary to judge whether the user input is legal at the front end, such as how many characters the name must be within, how many digits the phone number must be, and the mailbox must be in the mailbox format. The problem, in addition to the trouble, we now have a more elegant method (in the future, in the Python-related content, we will use the word "elegance" more and form a habit): ModelForm is simple first, use it bluntly, and then add Validation conditions.

 

Guess you like

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