close

[Solved] jinja2.exceptions.TemplateSyntaxError: expected token ‘end of print statement’, got ‘posted’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error jinja2.exceptions.TemplateSyntaxError: expected token ‘end of print statement’, got ‘posted’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How jinja2.exceptions.TemplateSyntaxError: expected token ‘end of print statement’, got ‘posted’ Error Occurs?

Today I get the following error jinja2.exceptions.TemplateSyntaxError: expected token ‘end of print statement’, got ‘posted’ in python.

How To Solve jinja2.exceptions.TemplateSyntaxError: expected token ‘end of print statement’, got ‘posted’ Error ?

  1. How To Solve jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got 'posted' Error ?

    To Solve jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got 'posted' Error You have to do <p>By {{ post['author'] }} on {{ post['date posted'] }} to make it work. it is a dict. So you have to get the values with indicies instead of calls.

  2. jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got 'posted'

    To Solve jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got 'posted' Error You have to do <p>By {{ post['author'] }} on {{ post['date posted'] }} to make it work. it is a dict. So you have to get the values with indicies instead of calls.

Solution 1

The line <p>By {{ post.author }} on {{ post.date posted }}</p> is the issue here

Replace it with <p>By {{ post.author }} on {{ post.date_posted }}</p>

post.date_posted is a variable and should be same as the one in your models, And spaces between them are obviously syntax errors(typos)

Solution 2

You have to do <p>By {{ post['author'] }} on {{ post['date posted'] }} to make it work. it is a dict. So you have to get the values with indicies instead of calls.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read