Use url_for() instead of relying on the request object