0
点赞
收藏
分享

微信扫一扫

分分钟开发一个网站——Python Django快速教程

大雁f 2022-04-06 阅读 121
python

一、开发环境配置

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.3

3、mysql安装

  • 下载地址 https://dev.mysql.com/downloads/installer/
  • 版本 8.0.28.0
  • 端口 默认3306,这里我使用了3308
  • root L@20220403
  • pip install mysqlclient
  • D:\soft\MySql8\MySQL Server 8.0\bin\添加到系统变量中mysql.exe改为mysql8.exe
  • 登录:mysql8 -uroot -P 3308 -p L@20220403
  • 查看mysql是否正常启动:WIN+R services.msc

二、Django初始配置

1、创建项目

  • 创建
  • 启动
  • 访问

2、创建应用

  • 创建一个应用 python manage.py startapp at

3、配置

  • settings.py
  • DATABASES
DATABASES = {

'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.py
def hello(request):

    context = {'hello': 'Hello World!'}

    return render(request, 'hello.html', context)
  • 创建模板 templates/at.html
<h1>{{ hello }}</h1>
  • at/urls.py
from django.urls import path

from . import views

urlpatterns = [

path(' ', views.hello, name='hello_name'),

]
  • urls.py

4、创建模型

  • 应用/models.py
  • 迁移命令
python manage.py makemigrations at
  • 显示sql
  • 创建表

5、创建管理员账号

  • 创建命令
python manage.py createsuperuser
  • 登陆

6、编写视图

  • 应用/views.py
  • 添加到应用/urls.py

FAQ

1、vscode报错:Import “django.contrib” could not be resolved from source PylancereportMissingModuleSource)

pip list查看是否安装了;设置中搜索python.analysis.extraPaths,再添加项添加包路径:

2、vscode报错:“include” is not definedPylancereportUndefinedVariable

添加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.json

3、Jenkins 嵌入到 Iframe

https://blog.csdn.net/github_39160845/article/details/108960606

4、安装插件

Blue Ocean

举报

相关推荐

0 条评论