Python Learning -- Django -- connect to the database mysql to create model, python -- django --
1.
Create a project
2.
Create the first page
3.
Create an app
4.
Add a page to the app
4.1
Configure in setting:
Add
Add
Create views
Then
You can access it through 127.0.0.1: 8000.
5.
Configure Database
Modify database information in setting
Check whether the database is connected
In my workbench, we can see that the default table is generated.
Next we will create a model by ourselves (we need to inherit models. Model)
Run commands
Then run
You can find that the table has been created.
Next, perform operations on the database.
I will insert two data entries in mysql first
Check that data has been inserted successfully
Then we
Modify the model to return the name, and modify views to display the returned result on the page.
You can see the result after running
This is the general process.