Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added url_for function for use in Jinja2 templates #124

Merged
merged 5 commits into from
Dec 6, 2022
Merged

added url_for function for use in Jinja2 templates #124

merged 5 commits into from
Dec 6, 2022

Conversation

kevinchai
Copy link
Contributor

Added the app.url_for function for use in Jinja2 templates as requested in #87.

Useful for referencing static files and endpoints in html templates. e.g.

  • {{ url_for('static', filename='styles.css') }}
  • {{ url_for('dashboard') }}

url_for is available within Jinja2 templates for Flask by default as part of the standard context (https://flask.palletsprojects.com/en/2.2.x/templating/). There may be other useful variables / functions to also add by default. e.g. session for logged in user details.

Copy link
Member

@ahopkins ahopkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great addition! Thanks. Can you add a quick test also?

@kevinchai
Copy link
Contributor Author

No worries. Just ran the tests with tox and fixed the identified errors with the second commit. Re-ran tests and they passed.

@ahopkins ahopkins merged commit 05b7ab8 into sanic-org:main Dec 6, 2022
@kevinchai kevinchai deleted the add-url-for-jinja branch March 2, 2023 09:57
@kevinchai kevinchai restored the add-url-for-jinja branch March 2, 2023 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants