Flask URL Building with url_for()


Flask Tip:

In Flask, the url_for() function builds the URL for a specific function.

url_for() is really useful in templates to easily include URLs.

👇

<header class="site-header">
  <a href="{{ url_for('stocks.index') }}">Flask App</a>
  <nav>
    <ul>
      <li><a href="{{ url_for('users.register') }}">Register</a></li>
      <li><a href="{{ url_for('users.login') }}">Login</a></li>
    </ul>
  </nav>
</header>