Python Learning--django--Connection database MySQL Create model

Source: Internet
Author: User

1.

Build a project


2.

Create first page


3.

Create an App


4.

Then add a page to the app

4.1

Inside the setting Configuration:


Add in My_project URL


Add in App1 's URLs


Create views


And then

You can access it through 127.0.0.1:8000.

5.

Configuration database

Modifying database information in setting


Check to see if the database is connected


In my workbench, I can see that the default table is generated


Next we build our own model (we need to inherit models. Model)


Run command


And then run


You can see that the table is created


Next work on the database

I'm going to insert 2 data into MySQL.


View discovery data has been successfully inserted


Then we

Modify the model to return the name and modify the views to display the returned results on the page



Results can be seen after running

That's the whole process, basically.







Python Learning--django--Connection database MySQL Create model

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.