/myapplication
/__init__.py
/views
/__init__.py
/admin.py
/frontend.py
/myapplication
/__init__.py
/app.py
/views
/__init__.py
/admin.py
/blog.py
# admin.py
from flask import Module
admin = Module(__name__)
@admin.route('/')
def index():
return "This is admin page!"
@admin.route('/profile')
def profile():
return "This is profile page."
# blog.py
from flask import Module
blog = Module(__name__)
@blog.route('/')
def index():
return "This is my blog!"
@blog.route('/article/<int:id>')
def article(id):
return "The article id is %d." % id
# app.py
from flask import Flask
from views.admin import admin
from views.blog import blog
app = Flask(__name__)
@app.route('/')
def index():
return "This is my app."
app.register_module(blog, url_prefix='/blog')
app.register_module(admin, url_prefix='/admin')
if __name__ == '__main__':
from werkzeug.serving import run_simple
run_simple('localhost', 5000, app)
def register_module(self, module, **options):
"""Registers a module with this application. The keyword argument
of this function are the same as the ones for the constructor of the
:class:`Module` class and will override the values of the module if
provided.
"""
options.setdefault('url_prefix', module.url_prefix)
state = _ModuleSetupState(self, **options)
for func in module._register_events:
func(state)
>>> app.url_map
Map([<Rule '/admin/profile' (HEAD, GET) -> admin.profile>,
<Rule '/admin/' (HEAD, GET) -> admin.index>,
<Rule '/blog/' (HEAD, GET) -> blog.index>,
<Rule '/' (HEAD, GET) -> index>,
<Rule '/blog/article/<id>' (HEAD, GET) -> blog.article>,
<Rule '/static/<filename>' (HEAD, GET) -> static>]
)
>>> app.url_map._rules_by_endpoint
{'admin.index': [<Rule '/admin/' (HEAD, GET) -> admin.index>],
'admin.profile': [<Rule '/admin/profile' (HEAD, GET) -> admin.profile>],
'blog.article': [<Rule '/blog/article/<id>' (HEAD, GET) -> blog.article>],
'blog.index': [<Rule '/blog/' (HEAD, GET) -> blog.index>],
'index': [<Rule '/' (HEAD, GET) -> index>],
'static': [<Rule '/static/<filename>' (HEAD, GET) -> static>]
}
>>> app.view_functions
{'admin.index': <function views.admin.index>,
'admin.profile': <function views.admin.profile>,
'blog.article': <function views.blog.article>,
'blog.index': <function views.blog.index>,
'index': <function __main__.index>
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有