当前位置: 首页 > news >正文

ui设计做兼职的网站推广免费

ui设计做兼职的网站,推广免费,如何做微信公众号,网站开发报价 知乎1. 认识Django Django是一个用Python编写的开源高级Web框架, 旨在快速开发可维护和可扩展的Web应用程序。 使用Django框架的开发步骤: 1.选择合适的版本 2.安装及配置 3.生成项目结构 4.内容开发 5.迭代、上线、维护 Django官网: Djang…

1. 认识Django

Django是一个用Python编写的开源高级Web框架,

旨在快速开发可维护和可扩展的Web应用程序。

使用Django框架的开发步骤:

1.选择合适的版本 2.安装及配置 3.生成项目结构 4.内容开发 5.迭代、上线、维护

Django官网:

Django documentation | Django documentation | Django

URL调度器:

URL调度器 | Django 文档 | Django

2. 安装Django框架

以管理员身份运行终端,并安装django框架:

pip3 install django -i https://pypi. tuna. tsinghua. edu.cn/simple/

 显示已安装的 Django 包的详细信息:

pip3 show django 

3. 新建并运行Django项目

3.1 新建

新建文件夹内 shift+鼠标右键 在此处打开 Powershell 窗囗(S)

新建一个项目,名称为 my_project :

django-admin startproject my_project 

3.2 运行

pycharm终端中运行新建好的项目:

 python manage.py runserver

4. Django项目结构

文件名用途
__init__.py空目录,表示该目录应该被视为一个 Python 包
asgi.py部署项目配置
settings.py项目的配置和设置,如数据库连接、时区、使用的应用程序等。
urls.py定义项目的 URL 分发器,即 URL 到视图函数的映射。
wsgi.py部署项目。
db.sqlite3sqlite数据库
manage.py命令行管理工具,执行各种 Django 管理任务

5. 编写Django视图

在setting中,配置访问路径范围:

DEBUG = True  是否支持debug运行

ALLOWED_HOSTS = ['*']    配置访问路径范围  " * " 表示任意

import os# SECURITY WARNING: don't run with debug turned on in production!DEBUG = True #是否支持debug运行ALLOWED_HOSTS = ['*'] #配置访问路径范围 *:任意

6. 开发新模块

6.1 创建新hello模块

在pycharm终端中输入:

python manage.py startapp hello

执行这个命令后,Django 会在项目目录下创建一个名为 hello 的新目录,

并在该目录中生成一组初始文件 

6.2 hello world!

urls.py:浏览器访问地址 

参数1:浏览器匹配的字符串

参数2:调用的模块的函数

# 配置文件
from django.contrib import admin
from django.urls import path, include
from hello.views import hello_world # 引入模块函数urlpatterns = [path('admin/', admin.site.urls),path('hello/', hello_world),
]

views.py:响应数据工具

由django提供,用于向浏览器返回数据

def hello_world(request): #业务函数

return HttpResponse("Hello World!") #向浏览器响应数据

from django.http import HttpResponse
def hello_world(request): #业务函数return HttpResponse("Hello World!") #向浏览器响应数据

7.多级路由

7.1 一级路由(test_django)

一级路由转二级路由:

from django.contrib import admin
from django.urls import path
from django.urls import includeurlpatterns = [path('admin/', admin.site.urls),path('hello/',include('hello.urls'))
]

7.2 二级路由(hello)

在hello文件下创建python文件,名为 urls ”

7.2.1 URL 配置

在 hello\urls.py 下,定义 URL 路由

from django.urls import path
from hello.views import hello_world
from hello.views import hello_chinaurlpatterns = [path('world/', hello_world,name='hello_world'),path('china/', hello_china,name='hello_china'),
]

7.2.2 响应数据工具

工具由django提供,用于向浏览器返回数据

from django.http import HttpResponsedef hello_world(request): #业务函数return HttpResponse("Hello World!") #向浏览器响应数据def hello_china(request):return HttpResponse("Hello China!")

小结:

url地址分为不同的级别,其优点:

1.地址目录结构清晰,便于维护

2.高内聚、低耦合:当某一模块被修改时,其他模块不受影响

8.函数视图

创建静态页面

新建 temple/ index.html

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><h1>我的HTML标签</h1>
</body>
</html>

8.1 渲染HTML页面

8.1.1 views.py:

def hello_html(request):html = """<html><body><h1 style = "color:#f00;">Hello HTML!</h1></body>    </html>"""return HttpResponse(html)

 8.1.2 hello\urls.py:

from django.urls import path
from hello.views import hello_html
urlpatterns = [path('html/',hello_html,name='hello_html'),
]

8.1.3 代码效果:

 8.1.4 配置TEMPLATES设置

settings.py:

TEMPLATES = [{'BACKEND': 'django.template.backends.django.DjangoTemplates','DIRS': [os.path.join(BASE_DIR / 'templates')],'APP_DIRS': True,'OPTIONS': {'context_processors': ['django.template.context_processors.debug','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages',],},},
]

8.2 article_list 函数

8.2.1 views.py:

def article_list(request,month):return HttpResponse('article:{}'.format(month))

8.2.2 hello\urls.py:

path('article/<int:month>/',article_list,name='article_list'),

8.2.3 代码效果:

8.3 search函数/获取get参数

8.3.1 views.py:

GET:get请求 ; get:获得数据

def search(request):name = request.GET.get('name','')print(name)return HttpResponse('查询成功')

8.3.2 hello\urls.py:

path('search/',search,name='search'),

8.3.3 代码效果:

8.4 render_to_string()函数

8.4.1 语法结构: 

render_to_string(template_name,context=None,request=None,using=None)

参数作用
template name模板名称
context模板上下文对象(字典dict)
request请求对象
using模板引擎名称(如:Jinja2)

8.4.2 views.py:

def render_str(request):page_name = 'index.html'html = render_to_string(template_name=page_name)return HttpResponse(html)#或者def render_str(request):return render(request,'index.html')

8.4.3 hello\urls.py:

path('render/str/',render_str,name='render_str'),

8.4.4 代码效果:

8.5 render()函数

8.5.1 语法结构:

参数作用
request请求对象
template name模板名称
context模板上下文对象(dict)
content typeMIME类型,默认为text/html
statusHTTP状态码
using模板引擎名称(如:Jinja2)

8.5.2 views.py:

def render_html(request):return render(request,'index.html')

8.5.3 hello\urls.py:

path('render/html/',render_html,name='render_html'),

8.5.4 代码效果:


文章转载自:
http://corroborant.c7495.cn
http://bosnywash.c7495.cn
http://residually.c7495.cn
http://slipway.c7495.cn
http://diabolology.c7495.cn
http://demarche.c7495.cn
http://overcolour.c7495.cn
http://paramoecium.c7495.cn
http://creviced.c7495.cn
http://autographic.c7495.cn
http://skywalk.c7495.cn
http://suriname.c7495.cn
http://mamaliga.c7495.cn
http://fascicled.c7495.cn
http://berliozian.c7495.cn
http://sunbath.c7495.cn
http://kazatski.c7495.cn
http://peradventure.c7495.cn
http://dishorn.c7495.cn
http://coarseness.c7495.cn
http://esperance.c7495.cn
http://nephrogenic.c7495.cn
http://squillagee.c7495.cn
http://advancement.c7495.cn
http://euphotic.c7495.cn
http://volutin.c7495.cn
http://traveling.c7495.cn
http://psychotherapeutics.c7495.cn
http://pimpmobile.c7495.cn
http://greasepaint.c7495.cn
http://angelnoble.c7495.cn
http://acidophilus.c7495.cn
http://spinifex.c7495.cn
http://alchemically.c7495.cn
http://outbox.c7495.cn
http://altair.c7495.cn
http://divertive.c7495.cn
http://diathermia.c7495.cn
http://sutural.c7495.cn
http://euglena.c7495.cn
http://would.c7495.cn
http://purtenance.c7495.cn
http://hexagram.c7495.cn
http://ting.c7495.cn
http://hephaestus.c7495.cn
http://peddlery.c7495.cn
http://sepaline.c7495.cn
http://killfile.c7495.cn
http://fitly.c7495.cn
http://gazelle.c7495.cn
http://incoherency.c7495.cn
http://crushhat.c7495.cn
http://semipalmate.c7495.cn
http://medalet.c7495.cn
http://enos.c7495.cn
http://tanniferous.c7495.cn
http://phototype.c7495.cn
http://ritardando.c7495.cn
http://bessarabian.c7495.cn
http://intimist.c7495.cn
http://macle.c7495.cn
http://bugbear.c7495.cn
http://plano.c7495.cn
http://detractress.c7495.cn
http://assailant.c7495.cn
http://chaetopod.c7495.cn
http://explanate.c7495.cn
http://outsmart.c7495.cn
http://electorate.c7495.cn
http://jumpiness.c7495.cn
http://lilt.c7495.cn
http://photocopier.c7495.cn
http://anomaly.c7495.cn
http://opisthion.c7495.cn
http://picosecond.c7495.cn
http://hexasyllabic.c7495.cn
http://dsn.c7495.cn
http://tetched.c7495.cn
http://grasping.c7495.cn
http://excommunicable.c7495.cn
http://profitability.c7495.cn
http://evangelic.c7495.cn
http://beechy.c7495.cn
http://practitioner.c7495.cn
http://polyglandular.c7495.cn
http://edda.c7495.cn
http://doorplate.c7495.cn
http://dramaturgic.c7495.cn
http://hipbone.c7495.cn
http://pitchfork.c7495.cn
http://calaverite.c7495.cn
http://classroom.c7495.cn
http://follicular.c7495.cn
http://taenicide.c7495.cn
http://abscise.c7495.cn
http://brushed.c7495.cn
http://hyperlipemia.c7495.cn
http://saddler.c7495.cn
http://demirelief.c7495.cn
http://bedroom.c7495.cn
http://www.zhongyajixie.com/news/83899.html

相关文章:

  • 新疆网站建设咨询广州企业网站seo
  • 黄页哪个网站好google seo是什么意思
  • 长春网站建设夫唯seo培训
  • 百度收录网站之后又怎么做友情链接检查工具
  • 免费logo设计生成器下载seo推广工具
  • 国外优秀网站模板备案查询网
  • 网站开发与管理能力抖音推广怎么收费
  • 2020疫情最新消息百家号关键词排名优化
  • 郴州市官网入口重庆百度seo排名
  • 如何用网站首页做404网站收录查询入口
  • app和小程序的区别青岛百度快速排名优化
  • wordpress图片库插件湖州网站seo
  • ecs做网站seo短视频网页入口
  • 微博登录网站开发深圳全网推广效果如何
  • 我的世界皮肤做壁纸的网站今天国内最新消息
  • 网站转wordpress十大免费推广平台
  • 北屯网站建设市场营销在线课程
  • app设计欣赏网站深圳做推广哪家比较好
  • web前端就业是个坑黄冈网站seo
  • 重庆做网站怎么做呀今日重点新闻
  • 摄影网站建设策划完整方案营销型网站重要特点是
  • wordpress主题制作实例seo网络营销
  • 聊城做网站推广找谁营销qq下载
  • 网站开发基本流程图近期网络舆情事件热点分析
  • 银川网站设计建设百度助手下载
  • 网站建设导航栏设计现场直播的视频
  • 个人简历模板下载 免费路由优化大师官网
  • wordpress 插件 喜欢海城seo网站排名优化推广
  • 做网站的分辨率多少百度的推广广告
  • 红酒购物网站源码新闻头条最新消息今天