一、开发环境配置1、python安装官网下载安装 https://www.python.org版本 3.10.4环境变量配置系统变量-path 添加:D:\soft\python310\python.exeD:\soft\python310\ScriptsVS 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 install mysqlclient环境变量配置D:\soft\MySql8\MySQLServer 8.0\bin\添加到系统变量中mysql.exe改为mysql8.exe登录:mysql8 -uroot -P 3308 -p L@20220403查看mysql是否正常启动:WIN+R services.msc二、Django初始配置1、创建项目创建 D:\soft\python310\Scripts\django-admin startproject devops启动python manage.py runserver访问 http://127.0.0.1:8000/2、创建应用创建一个应用python manage.py startapp at3、配置settings.pyLANGUAGE_CODE = 'zh-hans'INSTALLED_APPS:添加 'at'DATABASESDATABASES = {'default': {'ENGINE': 'django.db.backends.mysql', # 或者使用 mysql.connector.django'NAME': 'db_at','USER': 'root','PASSWORD': 'L@20220403','HOST': 'localhost','PORT': '3308',}}TEMPLATES'DIRS':[os.path.join(BASE_DIR, 'templates')],at/views.pydef hello(request):context = {'hello': 'Hello World!'}return render(request,'hello.html', context)创建模板 templates/at.html<h1>{{ hello }}</h1>at/urls.pyfrom django.urls import pathfrom . import viewsurlpatterns = [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//sqlmigrate 命令接收一个迁移的名称,然后返回对应的SQL创建表python manage.py migrate5、创建管理员账号创建命令python manage.py createsuperuser登陆http://127.0.0.1:8000/admin/ renjian01/123456a?6、编写视图应用/views.py添加到应用/urls.pyFAQ1、vscode报错:Import "django.contrib" could not beresolved from sourcePylancereportMissingModuleSource)pip list查看是否安装了;设置中搜索python.analysis.extraPaths,再添加项添加包路径:2、vscode报错:"include" is not definedPylancereportUndefinedVariable添加from django.urls import path, include三、Jenkins1、下载https://www.jenkins.io/download/下载war包,windows、liunx都可以用。admin/123456a?2、换源清华源https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json3、Jenkins 嵌入到 Iframehttps://blog.csdn.net/github_39160845/article/details/1089606064、安装插件Blue Ocean
本文出自快速备案,转载时请注明出处及相应链接。