therefore, each drawing must tell my base application how it wants to be named and what the default route is.
When creating a drawing, you already pass your name in the first parameter:
simple_page = Blueprint('simple_page')
You can also pass url_prefix to the constructor
simple_page = Blueprint('simple_page', url_prefix='/pages')
I have a main application that implements several routines as drawings. The main application should contain a navigation bar referring to all auxiliary applications (drawings)
This is an example in one python module, you have to separate each project in your own module.
from flask import Flask, Blueprint, render_template
admin = Blueprint('admin', __name__, url_prefix='/admin')
@admin.route('/')
def admin_index():
return 'Admin module'
@admin.route('/settings')
def settings():
return 'Admin Settings'
user = Blueprint('user', __name__, url_prefix='/user')
@user.route('/')
def user_index():
return 'User module'
@user.route('/profile')
def profile():
return 'User Profile'
app = Flask(__name__)
app.register_blueprint(admin)
app.register_blueprint(user)
@app.route('/')
def index():
return render_template('index.html', blueprints=app.blueprints)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True, port=7000)
Jinja2. , .
<ul>
{% for bp_name, bp in blueprints.iteritems() %}
<li><a href="{{ bp.url_prefix }}">{{ bp.name }}</a></li>
{% endfor %}
</ul>
, , ; app.blueprints, python , . , , URL .
, , , (, - ...)
, , Blueprint , .
custom.py
from flask import Blueprint
class MyBlueprint(Blueprint):
bp_data = {}
def set_data(data):
bp_data = data
admin.py
from .custom import MyBlueprint
admin = MyBlueprint('admin', __name__, url_prefix='/admin')
admin.set_data({'color': '#a569bd', 'enabled': true})
...
app.py
from admin import admin
app = Flask(__name__)
app.register_blueprint(admin)
@app.route('/')
def index():
for a, b in app.blueprints:
print b.bp_data['color']
print b.bp_data['enabled']
...
, Blueprint , , , , ; title, require_auth .. , .