Reputation: 8075
What is the proper way how to implement the following functionality:
The (Flask) web application view consists of several DIVs that contain some html content (ie, lists of items pulled from database). Once the view is downloaded to the browser, the content of the DIVs will be updated individually, depending on the user actions, by help of AJAX requests.
I know there are macros feature in the Jinja2 template engine that is part of the Flask micro framework. Perhaps there is a way how to render only certain macro, then I could use it to serve the partial content.
But then again, perhaps that is not the right way to achieve this functionality, and there is more "right" way.
Upvotes: 2
Views: 7101
Reputation: 43158
The Flask documentation actually has an example that does exactly what you describe:
Template:
{% macro hello(name) %}Hello {{ name }}!{% endmacro %}
View:
hello = get_template_attribute('_cider.html', 'hello')
return hello('World')
Upvotes: 2