Not a question per sae but an observation others may find helpful.
I have had issues with
'werkzeug.routing.BuildError: Could not build url for endpoint ... '
errors when using Flask to build a website.
As part of my development I had created a menu list item with a number of items with links as<a href="{{ url_for('home') }}">Home</a>
...
Later I wanted to modify the menus so commented out the HTML lines containing the original definitions with a <!-- ... -->
block. Struggling to get the code working, and to understand the syntax and relationships better, I modified single entities, the .py def name(), HTML file names, url_for() statements etc. to observe the impact.
Having understood the .py function name relating to the @app.route() decorator, as an aide memoir, I modified the home page function name in the .py to be "py_home_fn" and modified the url_for() to read url_for('py_home_fn') to match giving<a href="{{ url_for('py_home_fn') }}">Home</a>
I was perplexed to get
'werkzeug.routing.BuildError: Could not build url for endpoint 'home'. Do you mean 'py_home_fn' instead?'
being reported . Looking at the line number in the console, I noted that the line containing the error was within the commented section.
Changing the url_for('home') to be url_for('py_home_fn') in the HTML commented section, the error was no longer returned.
As a python/Flask nubie, this took me longer than I'd hoped and I haven't, so far, found any online references to this behaviour, although there are probably loads out there, so wanted to share.
The html comment tag <!-- ... -->
does not work in a jinja template. For commenting use the jinja comment tag ie, {# ... #}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With