Live well, love lots, and laugh often
Be kind to life, love everything, often laugh loudly
This article is mainly used to record the relevant parts of the Django model, the model can be simply understood as data operations, that is, to obtain data from the database, to store data in the database. Django uses sqlite3 by default and supports databases such as mysql and postgreSQL.
The default is sqlite3
Modified to mysql configuration:
NAME: The specified database name, if it is sqlite, you need to fill in the absolute location of the database file.
USER: User name for database login, mysql is generally root
PASSWORD: The password for logging in to the database must be the password corresponding to the USER user.
HOST: Since the general database is C/S structure, we have to specify the location of the database server. Our general database server and client are all on one host, so the default is 127.0.0.1.
PORT: database server port, mysql defaults to 3306
HOST and PORT can be left blank, using the default configuration
The following way is suitable for mysql, sqlite3 and other databases, in addition mysql needs to install mysql-python (pip install mysql-python)
Description: Create an auth table with the fields username, password, followed by the field data type and the maximum length.
Run: python manage.py shell
Description: The method used in View.py is similar to that in the shell.