Created
October 24, 2016 14:39
-
-
Save Stumblinbear/969b15a4e49a06a54a01542c53d1729b to your computer and use it in GitHub Desktop.
Note: "intended" only shows what I want to happen, while "current" shows (basically) the code I'm using.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask import render_template_string | |
from flask_menu import Menu, register_menu, current_menu | |
app = Flask(__name__) | |
Menu(app=app) | |
def tmpl_show_menu(): | |
return render_template_string( | |
""" | |
{%- for item in current_menu.children recursive %} | |
<a href="{{ item.url }}">{% if item.active %}*{% endif %}{{ item.text }}</a><br /> | |
{% if item.children %} | |
<ul> | |
{{ loop(item.children) }} | |
</ul> | |
{% endif %} | |
{% endfor -%} | |
""") | |
@app.route('/') | |
@register_menu(app, '.', 'Home') | |
def index(): | |
return tmpl_show_menu() | |
@app.route('/first') | |
@register_menu(app, '.first', 'First', order=0) | |
def first(): | |
return tmpl_show_menu() | |
@app.route('/second') | |
@register_menu(app, '.second', 'Second', order=1) | |
def second(): | |
return tmpl_show_menu() | |
@app.route('/third') | |
@app.route('/third/<uuid>') | |
@register_menu(app, '.third', 'Third', order=2) | |
def third(uuid): | |
return tmpl_show_menu() | |
def uuid_construct(uuid): | |
def wrapper(): | |
return {'uuid': uuid} | |
return wrapper | |
third = ['a', 'b', 'c'] | |
with app.app_context(): | |
for uuid in third: | |
item = current_menu.submenu('third.' + uuid) | |
item.register('third', uuid, 1, | |
endpoint_arguments_constructor=uuid_construct(uuid)) | |
if __name__ == '__main__': | |
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask import render_template_string | |
from flask_menu import Menu, register_menu, current_menu | |
app = Flask(__name__) | |
Menu(app=app) | |
def tmpl_show_menu(): | |
return render_template_string( | |
""" | |
{%- for item in current_menu.children recursive %} | |
<a href="{{ item.url }}">{% if item.active %}*{% endif %}{{ item.text }}</a><br /> | |
{% if item.children %} | |
<ul> | |
{{ loop(item.children) }} | |
</ul> | |
{% endif %} | |
{% endfor -%} | |
""") | |
@app.route('/') | |
@register_menu(app, '.', 'Home') | |
def index(): | |
return tmpl_show_menu() | |
@app.route('/first') | |
@register_menu(app, '.first', 'First', order=0) | |
def first(): | |
return tmpl_show_menu() | |
@app.route('/second') | |
@register_menu(app, '.second', 'Second', order=1) | |
def second(): | |
return tmpl_show_menu() | |
@app.route('/third') | |
@register_menu(app, '.third', 'Third', order=2) | |
def third(): | |
return tmpl_show_menu() | |
@app.route('/third/a') | |
@register_menu(app, '.third.a', 'a') | |
def third_a(): | |
return tmpl_show_menu() | |
@app.route('/third/b') | |
@register_menu(app, '.third.b', 'b') | |
def third_b(): | |
return tmpl_show_menu() | |
@app.route('/third/c') | |
@register_menu(app, '.third.c', 'c') | |
def third_c(): | |
return tmpl_show_menu() | |
if __name__ == '__main__': | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
current.py update