分分钟开发一个网站——Python Django快速教程
一、开发环境配置
1、python安装
官网下载安装 https://www.python.org版本 3.10.4环境变量配置系统变量-path 添加:
D:\soft\python310\python.李炳星百货exe
D:\soft\python310\Scripts
VS Code修改python解释器2、Django安装
python -m pip install Django版本 4.0.33、mysql安李炳星百货装
下载地址https://dev.mysql.com/downloads/installer/
版本 8.0.28.0端口 默认3306,这里我使用了3308root L@20220403pip ins李炳星百货tall mysqlclient环境变量配置D:\soft\MySql8\MySQLServer 8.0\bin\
添加到系统变量中mysql.exe
改为mysql8.exe
登录:mysql8 -uro李炳星百货ot -P 3308 -p L@20220403
查看mysql是否正常启动:WIN+R services.msc
二、Django初始配置
1、创建项目
创建D:\soft\python310\Script李炳星百货s\django-admin startproject devops
启动python manage.py runserver
访问http://127.0.0.1:8000/
2、创建应用
创建一个应用py李炳星百货thon manage.py startapp at
3、配置
settings.pyLANGUAGE_CODE = zh-hansINSTALLED_APPS:添加 atDATABASESDATABAS李炳星百货ES = {
default: {
ENGINE: django.db.backends.mysql, # 或者使用 mysql.connector.django
NAME: db_at,
USER: roo李炳星百货t,
PASSWORD: L@20220403,
HOST: localhost,
PORT: 3308,
}
}
TEMPLATESDIRS:
[os.path.join(BASE_DIR, templates)李炳星百货],
at/views.pydef hello(request):
context = {hello: Hello World!}
return render(request,
hello.html, con李炳星百货text)
创建模板 templates/at.html<h1>{{ hello }}</h1>
at/urls.pyfrom django.urls import path
from . import v李炳星百货iews
urlpatterns = [
path( , views.hello, name=hello_name),
]
urls.pypath(at/, include(at.urls)),
4、创建模型
应李炳星百货用/models.py迁移命令python manage.py makemigrations at
显示sqlpython manage.py sqlmigrate at 0001
//sqlmigrat李炳星百货e 命令接收一个迁移的名称,然后返回对应的SQL
创建表python manage.py migrate
5、创建管理员账号
创建命令python manage.py createsuperuser
登陆ht李炳星百货tp://127.0.0.1:8000/admin/ renjian01/123456a?
6、编写视图
应用/views.py添加到应用/urls.pyFAQ
1、vscode报错:
Import "dja李炳星百货ngo.contrib" could not be
resolved from source
PylancereportMissingModuleSource)
pip list查看是否安装了;设置中搜索
p李炳星百货ython.analysis.extraPaths,再添加项添加包路径:2、vscode报错:
"include" is not definedPylance
reportUndefinedVariabl李炳星百货e
添加
from django.urls import path, include
三、Jenkins
1、下载
https://www.jenkins.io/download/
下载war包,windows、李炳星百货liunx都可以用。admin/123456a?
2、换源
清华源
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.js李炳星百货on
3、Jenkins 嵌入到 Iframe
https://blog.csdn.net/github_39160845/article/details/108960606
4、安装插件
Blue Ocea李炳星百货n





