Day: January 27, 2023

Django详解之models操作

原文链接:https://www.cnblogs.com/allan-king/p/5807659.html Django 模型是与数据库相关的,与数据库相关的代码一般写在 models.py 中,Django 支持 sqlite3, MySQL, PostgreSQL等数据库,只需要在settings.py中配置即可,不用更改models.py中的代码,丰富的API极大的方便了使用。 1、数据库的连接方式以及设置: 在Django中默认使用的数据库类型是sqlite3,如果想要使用其他数据库就需要在settings中设置数据库的连接方式: # Database # https://docs.djangoproject.com/en/1.10/ref/settings/#databases   # sqlite3数据库连接方式 # DATABASES = { #     ‘default’: { #         ‘ENGINE’: ‘django.db.backends.sqlite3’, #         ‘NAME’: os.path.join(BASE_DIR, ‘db.sqlite3’), #     } # }   # MySQL数据库连接方式 DATABASES = { ‘default’: { […]

blueidea