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

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

Mysql - 标签 - cywhat's blog

Linux忘记mysql密码解决办法 Failing Package Is: Mysql Community Libs Compat 5.7.37 1.el7 Mac安装mysql5.7 Mysql连接以及增删改查语句 Centos7安装mysql5.7.41亲测可用
Django连接Mysql配置
cywhat · 2022-04-24 · via Mysql - 标签 - 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

关注一下再走吧

公众号 小程序

赞赏支持

微信打赏 支付宝打赏