快捷搜索:  汽车  科技

怎么开发一个网站(分分钟开发一个网站)

怎么开发一个网站(分分钟开发一个网站)WIN R services.mscmysql8 -uroot -P 3308 -p L@20220403D:\soft\MySql8\MySQLServer 8.0\bin\添加到系统变量中mysql.exe改为mysql8.exe

一、开发环境配置1、python安装
  • 官网下载安装 https://www.python.org
  • 版本 3.10.4
  • 环境变量配置

系统变量-path 添加:

D:\soft\python310\python.exe

D:\soft\python310\Scripts

  • VS Code修改python解释器

怎么开发一个网站(分分钟开发一个网站)(1)

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\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 at

3、配置
  • settings.py
    • LANGUAGE_CODE = 'zh-hans'
    • INSTALLED_APPS:添加 'at'
    • 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

path('at/' include('at.urls'))

4、创建模型
  • 应用/models.py
  • 迁移命令

python manage.py makemigrations at

  • 显示sql

python manage.py sqlmigrate at 0001

//sqlmigrate 命令接收一个迁移的名称,然后返回对应的SQL

  • 创建表

python manage.py migrate

5、创建管理员账号
  • 创建命令

python manage.py createsuperuser

  • 登陆

http://127.0.0.1:8000/admin/ renjian01/123456a?

6、编写视图
  • 应用/views.py
    • 添加到应用/urls.py
FAQ

1、vscode报错:

Import "django.contrib" could not be

resolved from source

PylancereportMissingModuleSource)

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

怎么开发一个网站(分分钟开发一个网站)(2)

2、vscode报错:

"include" is not definedPylance

reportUndefinedVariable

添加

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

怎么开发一个网站(分分钟开发一个网站)(3)

猜您喜欢: