惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
Jina AI
Jina AI
H
Help Net Security
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
L
LangChain Blog
Recorded Future
Recorded Future
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
GbyAI
GbyAI
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
M
MIT News - Artificial intelligence
爱范儿
爱范儿
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
B
Blog
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
MongoDB | Blog
MongoDB | Blog
Cloudbric
Cloudbric
N
News and Events Feed by Topic
The Cloudflare Blog
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
D
DataBreaches.Net
博客园 - 【当耐特】
T
Troy Hunt's Blog
V
Visual Studio Blog
V2EX - 技术
V2EX - 技术
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google Online Security Blog
Google Online Security Blog
The GitHub Blog
The GitHub Blog

Django - 分类 - cywhat's blog

Python创建并上传自己的pip依赖包 Django操作异步任务 ValueError:invalid UnorderedObjectListWarning:Pagination May Yield Inconsistent Results With an Unordered Object_list Django删除表重建 Django的csrf防御机制 RuntimeWarning:DateTimeField Session.expire_date received a naive datetime fonts.googleapis.com访问较慢[已解决] Django中的form表单校验
Django连接Mysql配置
cywhat · 2022-04-24 · via Django - 分类 - cywhat's blog

环境准备

1
2
3
编译环境:Python3.7.0
编辑器:Pycharm
解释环境:Virtualenv python=3.7.0

1.新建Django项目

各个代码编辑器都支持

安装Django和Mysql

1
2
3
pip3 install Django==1.11.7   #其他版本也可,Django后不加版本即可安装最新版

pip3 install pymysql

构建web应用

1
python3  manage.py startapp web 

2.修改Django配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',  # 默认
        'NAME': 'XXXX',  # 连接的数据库名
        'HOST': 'localhost',  # mysql的ip地址
        'PORT': 3306, # mysql的端口
        'USER': 'root',  # mysql的用户名
        'PASSWORD': 'XXXX'  # mysql的密码
    }
}

3.项目配置

1
2
3
4
5
#找到根目录项目中的__init__.py文件,输入以下内容
import pymysql


pymysql.install_as_MySQLdb()

4.数据更新

1
2
3
python3 manage.py makemigrations   #创建类数据库表

python3 manage.py migrate     #表数据写入(字段属性等)

5.库表数据查看

本地连接到数据库查看已经有了我们在models创建的表

/img/img59.png

关注一下再走吧

公众号 小程序

赞赏支持

微信打赏 支付宝打赏