当Web应用是子程序包时,我似乎无法在flask文档页面上复制任何最小示例
In [8]: from subpkg.apps.myapp import run_me
In [9]: run_me.main()
* Running on http://localhost:5050/ (Press CTRL+C to quit)
127.0.0.1 - - [10/Oct/2018 22:38:09] "GET / HTTP/1.1" 404 -
文件夹结构是一个较大的python库的一部分。例如,下面仅列出了包含代码的.py
文件
pkg/
-- setup.py
-- subpkg/
-- __init__.py
-- -- apps/
-- -- __init__.py
-- -- -- myapp/
-- -- -- -- __init__.py
-- -- -- -- run_me.py
-- -- -- -- web/
-- -- -- -- -- views.py
-- -- -- -- -- __init__.py
创建示例
mkdir pkg; mkdir pkg/subpkg/; mkdir pkg/subpkg/apps; mkdir pkg/subpkg/apps/myapp; mkdir pkg/subpkg/apps/myapp/web
touch pkg/__init__.py; touch pkg/subpkg/__init__.py; touch pkg/subpkg/apps/__init__.py; touch pkg/subpkg/apps/myapp/__init__.py; touch pkg/subpkg/apps/myapp/web/__init__.py; touch pkg/setup.py; touch touch pkg/subpkg/apps/myapp/web/views.py; touch pkg/subpkg/apps/myapp/run_me.py
pkg/setup.py
from setuptools import find_packages, setup
setup(
name='pkg-myapp',
packages=find_packages(),
include_package_data=True,
install_requires=['flask==0.11.1'],
entry_points={'console_scripts': ['pkg-myapp=pkg.apps.myapp.run_me:main',],},
)
pkg/subpkg/apps/myapp/run_me.py
from .web import app
def main():
app.run('localhost', 5050)
pkg/subpkg/apps/myapp/web/views.py
from . import app
@app.route("/")
def index():
return 'hello world'
pkg/subpkg/apps/myapp/web/__init__.py
from flask import Flask
app = Flask('subpkg.apps.myapp.web')