我用几个应用程序(如博客、代码、帐户等)实现了简单的站点。由于体积大,我决定将一个 python 文件拆分为应用程序。除了 Flask 的基本功能外,我不使用蓝图或其他东西——我想尽可能简单。不幸的是,flask 仍在寻找模板
/site
|-> main.py
from flask import Flask
app = Flask(__name__)
app.config.from_pyfile('config.py')
# Import all views
from errors.views import * # Errors hasn't its specific prefix
from blog.views import *
from account.views import *
from mysite.views import *
if __name__ == "__main__":
app.run(debug=True)
|-> templates
...................
|->blog
|-> template
|-> _layout.html
|-> index.html
|-> post.html
|-> __init__.py
from main import app
import blog.views
|-> views
from blog import app
from flask import render_template
@app.route("/blog/", defaults={'post_id': None})
@app.route("/blog/<int:post_id>")
def blog_view(post_id):
if post_id:
return "Someday beautiful post will be here with id=%s" % post_id
else:
return "Someday beautiful blog will be here"
@app.route("/blog/tags/")
def tags_view():
pass
..........................