Python Learning -- Django -- connect to the database mysql to create model, python -- django --

Source: Internet
Author: User

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.







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.