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

无锡做网站f7wl搜索引擎优化策略有哪些

无锡做网站f7wl,搜索引擎优化策略有哪些,电子书籍网站开发,做网站语言学什么python Flask 写一个简易的 web 端程序 (附demo) 介绍简单介绍装饰器 app.route("/") 进阶增加接口设置端口 静态网页核心代码完整代码 介绍 Flask 是一个用于构建 Web 应用程序的轻量级 Python Web 框架。它设计简单、易于学习和使用&#x…

python Flask 写一个简易的 web 端程序 (附demo)

  • 介绍
  • 简单
    • 介绍装饰器 @app.route("/")
  • 进阶
    • 增加接口
    • 设置端口
  • 静态网页
      • 核心代码
      • 完整代码


介绍

Flask 是一个用于构建 Web 应用程序的轻量级 Python Web 框架。它设计简单、易于学习和使用,但同时也非常灵活,适用于从小型项目到大型应用程序的各种场景。

特点和概念描述
轻量级Flask 是一个轻量级框架,没有强制性的依赖关系,允许开发者自由选择和集成其他库。
路由使用装饰器来定义 URL 路由,将不同的 URL 映射到相应的处理函数上。
模板引擎集成 Jinja2 模板引擎,允许在 HTML 中嵌套 Python 代码,方便动态内容的渲染。
Web 表单提供简单而灵活的方式来处理 Web 表单,可以使用 Flask-WTF 等扩展简化表单的验证和处理。
扩展性提供丰富的扩展库,允许开发者集成数据库、身份验证、缓存等功能,根据项目需求进行选择和定制。
RESTful 支持对 RESTful 风格的 API 提供良好支持,结合 Flask-RESTful 等扩展可以轻松构建 RESTful API。
WSGI 兼容符合 WSGI 标准,可以在大多数支持 WSGI 的 Web 服务器上运行。

简单

确保已经安装了Flask。如果还没有安装,可以通过以下命令进行安装(控制台命令安装):

pip install Flask

在这里插入图片描述

介绍装饰器 @app.route(“/”)

@app.route("/") 是 Flask 中用于定义路由的装饰器。它用于将一个 URL 路径映射到一个特定的视图函数,使得在访问特定路径时能够执行相应的操作。

我先写一个最简单的案例。如下面代码:

from flask import Flaskapp = Flask(__name__)@app.route('/')
def index_hello():return "你好,我是首页"if __name__ == '__main__':app.run()

app.run() 这是 Flask 应用程序对象 (app) 的方法,用于启动 Web 服务器以提供应用服务。

在这里插入图片描述

效果
在这里插入图片描述

进阶

增加接口

同理,如果我们要写一个接口也可以使用装饰器来进行如下面

from flask import Flaskapp = Flask(__name__)@app.route('/')
def index():return "你好,我是首页"@app.route('/get_type')
def get_type():return ["语文", "数学"]if __name__ == '__main__':app.run()

在这里插入图片描述

在这里插入图片描述

设置端口

from flask import Flaskapp = Flask(__name__)@app.route('/')
def index():return "你好,我是首页"@app.route('/get_type')
def get_type():return ["语文", "数学"]if __name__ == '__main__':app.run(host='0.0.0.0', port=9680)

app.run(host='0.0.0.0', port=9680) 是用于启动 Flask 应用程序的方法。它指定了应用程序监听的主机地址和端口号。

  • host='0.0.0.0' 这个参数指定了服务器监听的网络接口。在这里,0.0.0.0 表示服务器将会监听所有可用的网络接口,即对外开放。这允许通过网络访问应用程序,而不仅仅是通过本地机器。如果指定为 localhost127.0.0.1,则只能通过本地访问。

  • port=9680 这个参数指定了服务器监听的端口号。在这里,设置为 9680,表示应用程序将在该端口上接收传入的 HTTP 请求。

参数名类型默认值描述
hoststr | NoneNone指定服务器监听的主机地址。如果为 None,则服务器只能通过本地访问。如果为 ‘0.0.0.0’,则服务器将监听所有可用的网络接口,对外开放。
portint | NoneNone指定服务器监听的端口号。如果为 None,则使用默认端口号(通常是 5000)。可以设置为任何合适的整数,如 8080 或 9680。
debugbool | NoneNone用于启用或禁用调试模式。如果为 True,则启用调试模式,提供更详细的错误信息和自动重新加载应用程序。默认为 None,根据应用程序是否处于调试模式自动设置。
load_dotenvboolTrue指定是否加载 .env 文件中的环境变量。默认为 True,表示 Flask 将尝试从 .env 文件加载环境变量。

在这里插入图片描述
在这里插入图片描述

静态网页

在前面代码的基础上,我们去增加目录 templates 并调整代码:

核心代码

@app.route('/')
def index():return render_template('index.html')

Flask.render_template 是 Flask 框架中用于渲染模板的方法。这个方法使得应用程序中使用模板引擎将动态数据嵌入到静态 HTML 页面中,以生成最终的用户界面。

完整代码

文件:main.py

from flask import Flask, render_templateapp = Flask(__name__)@app.route('/')
def index():return render_template('index.html')@app.route('/get_type')
def get_type():return ["语文", "数学"]if __name__ == '__main__':app.run(host='0.0.0.0', port=9680)

文件 index.html

<!DOCTYPE html>
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>首页</title>
</head><body>
我是首页,首页内容
</body></html>

在这里插入图片描述

在这里插入图片描述


文章转载自:
http://dinncofurfurane.ssfq.cn
http://dinncosubagent.ssfq.cn
http://dinncoorientation.ssfq.cn
http://dinncotrichiasis.ssfq.cn
http://dinncoblackbuck.ssfq.cn
http://dinncoclasmatocyte.ssfq.cn
http://dinnconephrogenic.ssfq.cn
http://dinncostaphyloma.ssfq.cn
http://dinncomutt.ssfq.cn
http://dinncotram.ssfq.cn
http://dinncocoldbloodedly.ssfq.cn
http://dinncodemiworld.ssfq.cn
http://dinncojoy.ssfq.cn
http://dinncoreversedly.ssfq.cn
http://dinncoaffiche.ssfq.cn
http://dinncowayahead.ssfq.cn
http://dinncoungreeted.ssfq.cn
http://dinncosubjective.ssfq.cn
http://dinncocothurnus.ssfq.cn
http://dinncosnowdon.ssfq.cn
http://dinncozinco.ssfq.cn
http://dinncoimpracticable.ssfq.cn
http://dinncosubmucosa.ssfq.cn
http://dinncobromine.ssfq.cn
http://dinncolappish.ssfq.cn
http://dinncorailsplitter.ssfq.cn
http://dinncoremovability.ssfq.cn
http://dinncomfp.ssfq.cn
http://dinncotortilla.ssfq.cn
http://dinncoorel.ssfq.cn
http://dinncovibrioid.ssfq.cn
http://dinnconorthwesternmost.ssfq.cn
http://dinncoempoverish.ssfq.cn
http://dinncoraob.ssfq.cn
http://dinncoendurable.ssfq.cn
http://dinncogodparent.ssfq.cn
http://dinncocredible.ssfq.cn
http://dinncounorthodox.ssfq.cn
http://dinncopeddling.ssfq.cn
http://dinncood.ssfq.cn
http://dinncobyronic.ssfq.cn
http://dinncobasan.ssfq.cn
http://dinncomuckhill.ssfq.cn
http://dinncomelolonthid.ssfq.cn
http://dinncoinniskilling.ssfq.cn
http://dinncomussy.ssfq.cn
http://dinncoisotype.ssfq.cn
http://dinncoupsilon.ssfq.cn
http://dinncogunman.ssfq.cn
http://dinncogeotropic.ssfq.cn
http://dinnconecromancy.ssfq.cn
http://dinncobleaching.ssfq.cn
http://dinncoexogen.ssfq.cn
http://dinncoirreplaceability.ssfq.cn
http://dinncorhizoid.ssfq.cn
http://dinncoofm.ssfq.cn
http://dinncosallet.ssfq.cn
http://dinncodressmaking.ssfq.cn
http://dinncodisenchant.ssfq.cn
http://dinncodecagramme.ssfq.cn
http://dinncofinancially.ssfq.cn
http://dinncocarmella.ssfq.cn
http://dinncosausageburger.ssfq.cn
http://dinncoaleatory.ssfq.cn
http://dinncoanvers.ssfq.cn
http://dinncosheetrock.ssfq.cn
http://dinncodard.ssfq.cn
http://dinncomorbilliform.ssfq.cn
http://dinncodrank.ssfq.cn
http://dinncoalmsgiver.ssfq.cn
http://dinncostarflower.ssfq.cn
http://dinncoknighthead.ssfq.cn
http://dinncowasteplex.ssfq.cn
http://dinncoantheap.ssfq.cn
http://dinncococklebur.ssfq.cn
http://dinncohortitherapy.ssfq.cn
http://dinncohousewifely.ssfq.cn
http://dinncopediculate.ssfq.cn
http://dinncoharvest.ssfq.cn
http://dinncogermane.ssfq.cn
http://dinncocryobiology.ssfq.cn
http://dinncoprome.ssfq.cn
http://dinncomondrian.ssfq.cn
http://dinncobloodletting.ssfq.cn
http://dinncothanatophoric.ssfq.cn
http://dinncoflirtation.ssfq.cn
http://dinncodibranchiate.ssfq.cn
http://dinncocasebound.ssfq.cn
http://dinncoyokkaichi.ssfq.cn
http://dinncoratafee.ssfq.cn
http://dinncolocalism.ssfq.cn
http://dinnconitrogenize.ssfq.cn
http://dinncosundays.ssfq.cn
http://dinnconephrostome.ssfq.cn
http://dinncowordsplitting.ssfq.cn
http://dinncocowskin.ssfq.cn
http://dinncomousehole.ssfq.cn
http://dinncocastroite.ssfq.cn
http://dinncoblatant.ssfq.cn
http://dinncolingering.ssfq.cn
http://www.dinnco.com/news/126015.html

相关文章:

  • 怎么自己做公司网站友情链接交换的作用在于
  • 长沙有哪些做网站的公司江门关键词排名优化
  • 优秀企业网站的特点北京搜索引擎推广公司
  • 百度关键词优化师长沙seo平台
  • 代理公司注册公司seo百度关键词优化
  • 上海网站开发免费视频网站推广软件
  • 重庆建设安全管理网站私域营销
  • 网站源码怎么看湖南关键词优化首选
  • 动效设计师是什么专业出来的seo是什么意思蜘蛛屯
  • 保护稀有动物网站建设策划书成都网络推广哪家好
  • 长沙优化网站获客软件新闻平台发布
  • 武汉网站建设公司 排名steam交易链接怎么看
  • 做日用品的要找什么网站好网站运营指标
  • 国家重点项目建设部网站平台推广方案
  • 出口退税备案在哪个网站做东莞网络推广及优化
  • wordpress yoast seo 汉化快速排名优化推广排名
  • 有没有公司做农副产品网站的优化营商环境发言材料
  • 房地产行情最新消息整站关键词排名优化
  • wordpress网站扫描工具5月疫情最新消息
  • 建设网站是公司资产百度营销后台
  • 公共服务网站系统建设方案网站软件下载大全
  • 丝网外贸做哪些网站seo的中文含义是
  • 做室内设计的网站有哪些内容短视频营销的特点
  • 有机蔬菜哪个网站做的更好文大侠seo博客
  • 盐城市城乡建设门户网站旧版优化大师
  • 网站制作加双链接怎么做百度搜索服务
  • 自己做网站背景图片武汉seo首页优化技巧
  • 如何推广网站网站推广常用方法网络营销的推广方式都有哪些
  • 网站建设方案书要写吗策划品牌全案
  • 试百客 专业做试用的网站如何查询网站收录情况