TemplateSyntaxError

I have a beginner problem… I want to call a request.session.get from an html… this is the code…


    {% if request.session.get['sesioncarro']%}

        <th > Product</th>
    {% endif %}
        <th > Product</th> 
        
</tbody>

and the error is

TemplateSyntaxError at /ventasapp/ventas/

Could not parse the remainder: ‘[‘sesioncarro’]’ from ‘request.session.get[‘sesioncarro’]’

Request Method: GET
Request URL: http://127.0.0.1:8000/ventasapp/ventas/
Django Version: 5.1.1
Exception Type: TemplateSyntaxError
Exception Value: Could not parse the remainder: ‘[‘sesioncarro’]’ from ‘request.session.get[‘sesioncarro’]’
Exception Location: C:\Users\HP\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\base.py, line 706, in init
Raised during: ventasapp.views.ListaDventa
Python Executable: C:\Users\HP\AppData\Local\Programs\Python\Python312\python.exe
Python Version: 3.12.5
Python Path: ```
[‘C:\Users\HP\Desktop\python\Proyecto\webproyect’,
‘C:\Users\HP\AppData\Local\Programs\Python\Python312\python312.zip’,
‘C:\Users\HP\AppData\Local\Programs\Python\Python312\DLLs’,
‘C:\Users\HP\AppData\Local\Programs\Python\Python312\Lib’,
‘C:\Users\HP\AppData\Local\Programs\Python\Python312’,
‘C:\Users\HP\AppData\Local\Programs\Python\Python312\Lib\site-packages’]

Welcome @ricsot !

It would be request.session.sesioncarro.

Review the docs for Template API - Variables and lookups and Template Language - Variables

1 Like

Ken answered, but an other time you might also check the spaces near the %. You are missing a space before the last one. This might also lead to an error next time.

1 Like

Thank you very much for your time and willingness to help… grateful