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

相关推荐
郑州光合科技余经理7 小时前
同城系统海外版:一站式多语种O2O系统源码
java·开发语言·git·mysql·uni-app·go·phpstorm
ID_180079054738 小时前
基于 Python 的 Cdiscount 商品详情 API 调用与 JSON 核心字段解析(含多规格 SKU 提取)
开发语言·python·json
Q_Q5110082859 小时前
python+django/flask+vue的大健康养老公寓管理系统
spring boot·python·django·flask·node.js
我是哈哈hh9 小时前
【Python数据分析】Numpy总结
开发语言·python·数据挖掘·数据分析·numpy·python数据分析
Michelle80239 小时前
24大数据 14-2 函数练习
开发语言·python
qq_381454999 小时前
Python学习技巧
开发语言·python·学习
Ndmzi9 小时前
Matlab编程技巧:自定义Simulink菜单(理解补充)
前端·javascript·python
dagouaofei10 小时前
AI生成个性化年终总结PPT
人工智能·python·powerpoint
爱吃面条的猿10 小时前
MySQL 随机日期/时间生成
数据库·mysql
2501_9399090510 小时前
Mysql 主从复制、读写分离
数据库·mysql