Question: Hello I have a problem with a select/option html where you can select the page number, so page 1 of 100, 2 of 200 etc... and then goes to page 1, 2, 3 ...

Everything works in the following code apart from the fact that inside the select button, after clicking on the page you want to go, after refreshing the page, it goes back to page 1, it always shows: page 1 of 100, even if actually in the url the page number is correct. I should use a session variable, but the problem is that I'm struggling to understand how to use it with Flask/Jinja2 directly in the html page. Someone can help?

using `{% set session['page'] = page %}` and then `{{ session['page'] }}` it gives me syntax error:

```
TemplateSyntaxError: expected token 'end of statement block', got '['

```

```
{% set session['page'] = page %}
    <select onchange="window.location.href=this.value">

        {%- for page in range (1,(form.total_PAGE.data | int) + 1 ) %}

            <option value="{{ page }}">{{ session['page'] }}/{{ form.total_PAGE.data }}</option>
        {%- endfor %}
    </select>

```

Answer: 
In general, you cannot assign to an object atribute using `set`, neither using `obj['attr']` or `obj.attr` syntax (see [the documentation](http://jinja.pocoo.org/docs/2.10/templates/#assignments)). However, you can enable the [expression-statement extension](http://jinja.pocoo.org/docs/2.10/templates/#expression-statement) and then set the attribute using dict update like this:

```
{% do session.update({'page': page}) %}

```

But as already stated in the comment, this doesn't really make sense and can be solved more cleanly using other approaches.
I have tested what mentioned by Tomáš Linhart but not worked for me as [I did not update Expression statement extension](https://stackoverflow.com/questions/39858191/do-statement-not-working-in-jinja#answer-39858522) and modify default what worked to assign a session variable in jinja2 flask is:

```
  {% if session.update({session_var_name: []}) %}{% endif %}

```