Python Learning -- Django -- connect to mysql to create a model
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 I beer "http://www.bkjia.com/kf/web/php/" target = "_ blank" class = "keylink"> mixer + bJz8/Uyr63tbvYtcS94bn7PC9wPgo8cD48aW1nIHNyYz0 = "http://www.2cto.com/uploadfile/Collfiles/20150418/2015041809521718.png" alt = "\">
You can see the result after running
This is the general process.