close

[Solved] TemplateSyntax: expected token ‘:’, got ‘}’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error TemplateSyntax: expected token ‘:’, got ‘}’ 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 TemplateSyntax: expected token ‘:’, got ‘}’ Error Occurs?

Today I get the following error TemplateSyntax: expected token ‘:’, got ‘}’ in python.

How To Solve TemplateSyntax: expected token ‘:’, got ‘}’ Error ?

  1. How To Solve TemplateSyntax: expected token ':', got '}' Error ?

    To Solve TemplateSyntax: expected token ':', got '}' Error Don't do more {{}} inside of other {{}} blocks.

  2. TemplateSyntax: expected token ':', got '}'

    To Solve TemplateSyntax: expected token ':', got '}' Error Don't do more {{}} inside of other {{}} blocks.

Solution 1

Don’t do more {{}} inside of other {{}} blocks.

Here’s my url_for() call:

<a href="{{ url_for('viewBlog', userid=item.userid)}}"></a>

I was getting that same error when it looked like this:

<a href="{{ url_for('viewBlog', userid={{item.userid}}) }}"></a>

Once I removed the inner {{}}, the problem went away.

Solution 2

<div class="delete-file"><a href="{{ url_for('.delete_file', file_name={{ file.filename }} ) }}">Delete File</a></div><br>

You cannot call a function directly from django template like above. Write custom template tags to satify your purpose.

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