Django Development (II) "Models"

Source: Internet
Author: User

Python 2.7.6

Django1.8.3

IDE Eclipse+pydev


The Django development model is the MTV (c) mode (model, template, view (URLs)).

For the model I understand that each of the classes in the App.models corresponds to the table of each database, and models is the main definition of a table, interacting with the database, the data to be added and censored, and so on, which is the core of a site storage data.

To create a good models first to build a database, if you want to use the database is SQLite, then you do not need to set up, if you want to use a database such as MySQL, You need to set setting.py, a dictionary of databases in setting.py, as follows (I'm using MySQL)

DATABASES = {
' Default ': {
' ENGINE ': ' Django.db.backends.mysql ',//If you are using SQLite user and the following three lines are not required
' Name ': ' Hello ', (Hello is the name of the database)
"User": "User",
"PASSWORD": "PASSWORD",
"HOST": "",
"PORT": "",
}
}


After setting up the database, you also need to create a database corresponding to the app, and the database name is the value corresponding to ' name ' above.

To create a MySQL database named Hello in the terminal, enter it in the terminal:

Msql-u user-pxxxxxxxxcreate Databases Hello
The database is created

Then click on the project you want to work with in eclipse right-select Django make migration migrate you have successfully created a table

You can enter it at MySQL Terminal:

Use helloshow tables
You can see the database table you just created


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Django Development (II) "Models"

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.