0

I have a Jinja2 Template that I am serving in flask that looks somthing like this:

{% if current_user.UserType == “Admin” %}
Stuff
{% endif %}

However I am getting an error like this

TemplateSyntaxError: unexpected char u'\u201c' at 860

What is the proper way to check a key's value in Jinja2?

Mark Omo
  • 898
  • 2
  • 12
  • 26
  • 1
    I think you're doing it correctly, the problem looks like those [fancy/curly quotes](http://stackoverflow.com/questions/3428876/how-to-remove-curly-quotes) around `“Admin”`; see [UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 34: ordinal not in range(128)](http://stackoverflow.com/questions/24264892/unicodeencodeerror-ascii-codec-cant-encode-character-u-u201c-in-position-3) – chickity china chinese chicken Mar 14 '17 at 00:15
  • You're right, thanks for some reason Jekyll was converting the quotes to the fancy ones – Mark Omo Mar 14 '17 at 00:18

2 Answers2

0

It looks like the problem was the one downshift mentioned with encoding, I was under the impression that it was somthing to do with the jinja2 syntax but,

{% if current_user.UserType == "Admin" %}
Stuff
{% endif %}

works just fine.

Mark Omo
  • 898
  • 2
  • 12
  • 26
-1

Use bracket notation:

{% if current_user["UserType"] == “Admin” %}
Stuff
{% endif %}

Or the get method:

{% if current_user.get("UserType") == “Admin” %}
Stuff
{% endif %}

Also use Google

Allie Fitter
  • 1,689
  • 14
  • 18