4007654355
NEWS
网站建设、网站制作、网站设计等相关资讯

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

日期:2024-05-07 访问:792次 作者:admin

一、开发环境配置

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,这里我使用了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:添加 atDATABASES

DATABAS李炳星百货ES = {

default: {

ENGINE: django.db.backends.mysql, # 或者使用 mysql.connector.django

NAME: db_at,

USER: roo李炳星百货t,

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, con李炳星百货text)

创建模板 templates/at.html

<h1>{{ hello }}</h1>

at/urls.py

from django.urls import path

from . import v李炳星百货iews

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

//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.py

FAQ

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



智投管家·竞价专家  SEO优化:筑牢防坑壁垒,安全提升排名  ChatGPTPlus使用体验-智能助手的全新升级  句子改写器在线:智能化写作的得力助手,提升文章质量的秘密武器  好的网络推广企业,助力企业实现数字化腾飞,长春seo排名选哪家  “京速优排,一跃而上”  专业的SEO优化推广,让您的网站排名稳居前列  SEO优化指数,提升排名秘籍  企业抖音运营的真正步骤有哪些?  大二网络营销实训,技能提升显著  打造专属网址,轻松上线!  SEO顾问教你如何提升网站排名技巧  影视解说文案生成器破解版下载让影视解说创作变得更加轻松与高效  自学SEO如何做营销:从零到精通的营销秘籍  “精准投放,搜索流量翻倍,品牌知名度飙升!”  网站链接管理页面:让您的网站链接管理更高效  短视频带货,如何起号更吸引人?  如何登上抖音热门榜单?  ChatGPT连接不上?如何解决常见问题,畅享智能对话体验!  重庆百度优化关键词精炼  SEO教学:从零到一搜索引擎优化的秘密  快速排名优化费用:如何在短时间内提升网站排名,最大化投入产出比  破解ChatGPT的极限:让你体验前所未有的人工智能优势  屏南SEO新攻略:关键词精准,内容原创,链接广泛。  GPT3开源了吗?揭秘GPT3技术背后的秘密与未来潜力  家纺家居装饰类网站模板  GPT3.5在线应用:重新定义智能写作与创作体验  礼品工艺品SEO培训,网站SEO实战技巧  重庆高端SEO:提升品牌曝光度,助力企业腾飞  分销系统当中的供货商系统原来有这些功能