Issue
at app init i'm dynamically loading URL's from the DB, adding them with app.add_url()
.
As the behavior is CMS like, my user can delete or change the url for some pages so i need to sometimes delete a mapping or reload all url mappings.
Does anyone know a way to do this?
Thanks
Solution
Flask (which relies on Werkzeug) is designed to allow the user to easily add, not delete, routes. However you can try to delete routes yourself; each route is added to url_map
in the Flask.add_url_rule()
method. It is probably enough to remove the route from Map._rules
and Map._rules_by_endpoint
(see the Map.add()
method) and call Map.update()
with _remap
.
But this will not work in general, for example when creating a route that delegates to a view function in a separate dict
:
_routes = {}
@app.route('/<path:url>', methods=['GET', 'POST'])
def route(url):
handler = _routes.get(url, None)
if handler is not None:
return handler()
abort(404)
Answered By - tbicr
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.