I want to somehow check if a endpoint has a decorator like login_required
, is there a way I could do it?
This is how I get all url_rules:
def has_no_empty_params(rule):
defaults = rule.defaults if rule.defaults is not None else ()
arguments = rule.arguments if rule.arguments is not None else ()
return len(defaults) >= len(arguments)
def sitemap():
links = []
for rule in
if "GET" in rule.methods and has_no_empty_params(rule):
url = flask.url_for(rule.endpoint, **(rule.defaults or {}))
links.append((url, rule.endpoint))
return links
This is my navigation bar in which I use these, but I want to somehow not display the views who have the decorator login_required.
{% for url, endpoint in endpoints %}
{% if request.url_rule != endpoint %}
<a href="{{ url }}">
<button class="tablecontent">{{ endpoint.split('.', 1)[1] }}</button>
</a>
{% endif %}
{% endfor %}
I am sorry for the late edit, but if someone is still here, any help would be appreciated. Or maybe I should better hard code the view names in a dictionary?