Django-配置mysql

注意:需要在项目中安装mysqlclient包

setting文件数据库相关修改:

python 复制代码
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mysite3',
        'USER': 'root',
        'PASSWORD': 'bai12345',
        'HOST': '127.0.0.1',
        'PORT': '3306',
    }
}

什么是模型?:

ORM框架:

注册app需要在setting中添加:

python 复制代码
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'music',
    'news',
    'sport',
    'bookstore'
]
python 复制代码
from django.db import models


# Create your models here.
class Book(models.Model):
    title = models.CharField("书名", max_length=100)
    author = models.DecimalField('价格', max_digits=10, decimal_places=2)

执行后结果: 生成的表名为app名_小写类名

相关推荐
Q_Q51100828520 分钟前
python+django/flask的眼科患者随访管理系统 AI智能模型
spring boot·python·django·flask·node.js·php
SunnyDays10112 小时前
如何使用Python高效转换Excel到HTML
python·excel转html
Q_Q5110082852 小时前
python+django/flask的在线学习系统的设计与实现 积分兑换礼物
spring boot·python·django·flask·node.js·php
Q_Q5110082853 小时前
python+django/flask的车辆尾气检测排放系统-可视化大屏展示
spring boot·python·django·flask·node.js·php
汤姆yu3 小时前
2026版基于python大数据的旅游可视化及推荐系统
python·旅游·大数据旅游
angleoldhen4 小时前
简单的智能数据分析程序
python·信息可视化·数据分析
颜大哦4 小时前
linux安装mysql
linux·运维·mysql·adb
youzj09254 小时前
docker网站配置
python
snowfoootball4 小时前
python函数及面向过程高级特性
开发语言·python
DP+GISer4 小时前
基于站点数据进行遥感机器学习参数反演-以XGBOOST反演LST为例(附带数据与代码)试读
人工智能·python·机器学习·遥感与机器学习