我正在尝试运行一个简单的连接REST-API。 我已经在run.py上实例化了connexion的实例。
import os
import connexion
from flask import render_template
from people import read
app = connexion.App(name, specification_dir=’./’)
app.add_api(‘swagger.yaml’)
@app.route(‘/’)
def home():
return ‘Welcome to users API’
if name == ‘main’:
app.run(port=’5000′, host=’0.0.0.0′, debug=True)
服务器swagger.yaml Swagger规范
swagger: “2.0”
info:
description: Auth users details
version: “1.0.0”
title: Swagger specification for the Auth contracts
consumes:
- “application/json”
produces:
- “application/json”
basePath: “/api”
paths:
/users:
get:
operationId: “users.read”
tags:
- “Users”
summary: “The users data structure supported by the server application”
description: “Read the list of users”
responses:
200:
description: “Successful read users list operation”
schema:
type: “array”
items:
properties:
fname:
type: “string”
lname:
type: “string”
timestamp:
type: “string”
应用程序的用户详细信息。 users.py
from datetime import datetime
def get_timestamp():
return datetime.now().strftime((“%Y-%m-%d %H:%M:%S”))
users = {
‘Tom’: {
‘fname’: ‘Tom’,
‘lname’: ‘Riddle’,
‘timestamp’: get_timestamp()
‘Harry’: {
‘fname’: ‘Harry’,
‘lname’: ‘Potter’,
‘timestamp’: get_timestamp()
‘Dumbledore’: {
‘fname’: ‘Brian’,
‘lname’: ‘Dumbledore’,
‘timestamp’: get_timestamp()
def read():
return [users[key] for key in sorted(users.keys())]
对于延迟启动,我创建了外壳文件server.sh
export FLASK_APP=run.py
export FLASK_DEBUG=1
flask run
应用程序的文件夹结构。
W/D
├── pycache
│ ├── init.cpython-37.pyc
│ ├── people.cpython-37.pyc
│ ├── run.cpython-37.pyc
│ └── users.cpython-37.pyc
├── run.py
├── server.sh
├── swagger.yaml
└── users.py
当我运行外壳程序时,会出现此错误。
flask.cli.NoAppException: Failed to find Flask application or factory in module “run”. Use “FLASK_APP=run:name to specify one.
这里可能是什么问题?
Original: https://blog.csdn.net/weixin_42102713/article/details/114967564
Author: KINSLAUGHTER
Title: python在工厂中的应用_python – 无法在“运行”模块中找到Flask应用程序或工厂 – 堆栈内存溢出…
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/748999/
转载文章受原作者版权保护。转载请注明原作者出处!