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名_小写类名

相关推荐
唐璜Taro4 分钟前
Agent Harness 系列 · 第 1 篇|Agent 不只是换一个更强的模型
人工智能·python
泡茶喝茶写代码30 分钟前
量化数据进阶:多维实战篇(第 11 篇):历史涨跌停价:涨跌停序列与止损线测算
java·python·股票数据api·股票数据·股票数据api接口·股票api数据接口·股票量化数据api
ikun_文1 小时前
Django开启跨域请求
python·pycharm·django
外收内放1 小时前
Python与AI应用(项目开发实战:AI智能伴侣第三版)
python·学习·ai编程
别动我齐刘海1 小时前
ROS2 Jazzy + C++ 实战路线——进阶学习3
c++·人工智能·vscode·python·算法·机器学习·机器人
Logintern091 小时前
“以一致的顺序获取锁“是预防死锁最核心、最有效的手段
python·postgresql·锁机制
打工仔折腾 AI2 小时前
Prometheus 告警推钉钉:从单群 Webhook 到跨网络 Alertmanager 实战
人工智能·后端·python·性能优化
Ivanqhz2 小时前
Ping-Pong 双缓冲
开发语言·人工智能·python·深度学习·mlir
三十岁老牛再出发2 小时前
9月18日总结
python·深度学习·机器学习
就叫你天选之人啦2 小时前
安装torch+vllm+flash_attn的prompt
人工智能·pytorch·python