上來(lái)就干貨!
1、創(chuàng)建虛擬目錄
python -m venv saasvenv
2、啟動(dòng)虛擬目錄
saasvenv\Scripts\activate
退出虛擬目錄
deactivate
3、創(chuàng)建django項(xiàng)目
django-admin startproject saas
4、cd saas 創(chuàng)建項(xiàng)目應(yīng)用
python manage.py startapp users
5衡创、修改配置
6、數(shù)據(jù)庫(kù)操作
創(chuàng)建數(shù)據(jù)庫(kù)
create database saas charset 'utf8';
刪除數(shù)據(jù)庫(kù)
drop database saas
刪除表
drop table user
新建mysql用戶
create user 'saas'@'%' identified by 'password';
刪除用戶
drop user 'saas'@'%';
修改用戶密碼
alter user 'saas'@'%' identified by 'saas222';
授權(quán)訪問(wèn)數(shù)據(jù)庫(kù)
grant all on saas.* to 'saas'@'%';
刷新權(quán)限
flush privileges;
遷移
python manage.py makemigrations
python manage.py migrate
啟動(dòng)
python manage.py runserver
查看所有路由
python manage.py show_urls
pip install
django
mysqlclient
# 前后端分離+token
djangorestframework
djangorestframework-simplejwt
# 圖形驗(yàn)證碼
django-simple-captcha
ps:提示包資源不存在晶通,有可能是虛擬環(huán)境沒(méi)選對(duì)璃氢,pip install 到全局去了,查看saasvenv\Lib\site-packages\下的包是否存在
pip freeze > requirements.txt
pip install -r requirements.txt
vscode python 導(dǎo)入自定義包失敗
1狮辽、在.vscode/launch.json文件加入如下配置
{
"version": "0.2.0",
"configurations": [
{
// ...其他配置
"env": {"PYTHONPATH":"${workspaceRoot}"},
"envFile": "${workspaceRoot}/.env"
}
]
}
2一也、根目錄下添加.env文件巢寡,內(nèi)容如下:
PYTHONPATH=./包的上一級(jí)目錄;
eg: 導(dǎo)入 ./saas/utils/xx.py
PYTHONPATH=./saas;
數(shù)據(jù)庫(kù)導(dǎo)出
python manage.py dumpdata > backup.json
數(shù)據(jù)庫(kù)導(dǎo)入
python manage.py loaddata babckup.json