“python manage.py runserver”在下面的情况下运行。它不运行main.py或app包。
烧瓶
myApp
main.py
bash> python main.py
flask_script
manage.py
myApp
__init__.py
main.py
bash> python manage.py runserver
manage.py
from flask_script import Manager
from myApp import app
manager = Manager(app)
if __name__ == "__main__":
manager.run()
main.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return "Hello World"
if __name__ == '__main__':
app.run(debug=True)
且__init__.py
为空
答案 0 :(得分:0)
我回答自己的问题,因为每当我在这个热情友好的社区中提出任何要求时,我都会得到任意的弊端。
我发现“一种方式”可能不是“方式”。
文件结构
|manage.py
|myApp
|__init__.py
|main.py
|blog
|__init__.py
|blog.py
<强> manage.py 强>
from flask_script import Manager
from flask import Flask
from myApp.main import interface as main_inaterface
from myApp.blog.blog import interface as blog_interface
app.register_bluprint(main_interface, url_prefix='/main')
app.register_bluprint(blog_interface, url_prefix='/blog')
manager = Manager(app)
if __name__ == '__main__':
manager.run()
myApp .__ init __。py
from flask import Flask
app = Flask(__name__)
import myApp
main.py
from flask import Blueprint
interface = Blueprint('myApp', __name__)
@interface.route('/')
def hello():
return "from main"
<强>博客强>
from flask import Blueprint
interface = Blueprint('blog', __name__)
@interface.route('/')
def blog():
return "From Blog"