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

推荐订阅源

K
Kaspersky official blog
Martin Fowler
Martin Fowler
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
博客园_首页
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
MongoDB | Blog
MongoDB | Blog
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
雷峰网
雷峰网
D
Docker
博客园 - 司徒正美
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
U
Unit 42
J
Java Code Geeks
A
About on SuperTechFans
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security Affairs
I
Intezer
Cisco Talos Blog
Cisco Talos Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
B
Blog RSS Feed
P
Privacy & Cybersecurity Law Blog
T
Tenable Blog
T
Threatpost
H
Hacker News: Front Page
G
Google Developers Blog
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
L
Lohrmann on Cybersecurity
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
S
Secure Thoughts
GbyAI
GbyAI
NISL@THU
NISL@THU
S
Security @ Cisco Blogs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Webroot Blog
Webroot Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
O
OpenAI News
Spread Privacy
Spread Privacy
Application and Cybersecurity Blog
Application and Cybersecurity 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

关注一下再走吧

公众号 小程序

赞赏支持

微信打赏 支付宝打赏