python使用flask框架实现http服务处理

1,python使用flask框架实现http接口与html的返回
1,py文件同级建立文件夹 templates
2,把html文件放进去 命名为hello.html
html代码

<!DOCTYPE html>
<html>
<head>
    <title>Hello</title>
</head>
<body>
    <h1>Hello, {
  { name }}!</h1>
</body>
</html>

python代码

from flask import Flask, render_template

app = Flask(__name__)


@app.route('/test')
def index():
    return 'Hello, World!Py'


@app.route('/hello/<name>')
def hello(name):
    return render_template('hello.html', name=name+'Py')


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=80)

3,启动后 访问 
	http://127.0.0.1/hello/name
	http://127.0.0.1/hello/test
	看执行效果

相关推荐

  1. python使用flask框架实现http服务处理

    2023-12-07 10:14:02       53 阅读
  2. Flask与Celery实现Python调度服务

    2023-12-07 10:14:02       27 阅读
  3. Python实战Flask轻量级web框架入门

    2023-12-07 10:14:02       46 阅读
  4. 基于libevent使用c语言实现http服务端的基础框架

    2023-12-07 10:14:02       59 阅读
  5. Python Flask 框架开发

    2023-12-07 10:14:02       64 阅读
  6. pythonFlask Web框架

    2023-12-07 10:14:02       51 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-07 10:14:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-07 10:14:02       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-07 10:14:02       82 阅读
  4. Python语言-面向对象

    2023-12-07 10:14:02       91 阅读

热门阅读

  1. Redis 底层数据结构 - 简单动态字符串

    2023-12-07 10:14:02       52 阅读
  2. 【ML】LSTM应用——预测股票(基于 tensorflow2)

    2023-12-07 10:14:02       58 阅读
  3. ffmpeg 同时采集麦克风和摄像头并录制文件

    2023-12-07 10:14:02       37 阅读
  4. RDMA编程实例rdma_cm API

    2023-12-07 10:14:02       35 阅读
  5. Spring Boot 容器如何根据注解加载发现与管理组件

    2023-12-07 10:14:02       37 阅读