Forums

TypeError: render_template() takes exactly 1 argument (5 given)

I am trying to pass variables using Flask to Jinja2 templates. The variables are: url_start, url_end, articles_1 (list) and a counter (counter_page_two).

Attempted the code below.

return render_template('page_two.html', url_start, url_end, articles_1, counter_page_two)

However, when I do so I get the error message in the subject. TypeError: render_template() takes exactly 1 argument (5 given)

Flask documentation has this:

flask.render_template(template_name_or_list, **context)

Renders a template from the template folder with the given context.

Parameters: template_name_or_list – the name of the template to be rendered, or an iterable with template names the first one existing will be rendered context – the variables that should be available in the context of the template.

So, in theory I should be able to pass as many variables as I like.

Any thoughts on why I am getting the error?

The ** means that it's looking for keyword args. So you should be using something more like:

return render_template('page_two.html', url_start=url_start, url_end=url_end, articles=articles_1, counter=counter_page_two)

or something like that. Each of the values will then be available in your template depending on the name you gave them in the arguments list.