What is the purpose of Flask's `url_for` function?
Instruction: Explain how `url_for` works and provide examples of its usage.
Context: This question checks the candidate's understanding of generating URLs in Flask applications, emphasizing the benefits of using `url_for` for maintainability.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
url_for builds a URL for a registered endpoint and its route values. The endpoint is usually the view function name, prefixed by a blueprint name when applicable. It allows links to follow changed route paths without hardcoding those paths in every caller.
```python from flask import Flask, url_for...