Consider this Flask Jinja2 template snippet:
{% if current_user.is_admin %}
{% else %}
You do not have permission to delete posts.
{% endif %}If current_user.is_admin is False, what will be rendered?
Think about how the {% if %} condition controls what is shown.
The template checks if current_user.is_admin is true. If false, it shows the <p> message. So option A is correct.
Which option contains a syntax error in this template authorization snippet?
{% if user.is_authenticated and user.is_admin %}
Welcome, admin!
{% endif %}Check the logical operator syntax in Jinja2.
Jinja2 uses and not && for logical AND. Option A uses invalid &&, causing a syntax error.
Given this Flask template snippet:
{% if user.is_authenticated %}
{% if user.is_admin %}
Admin Panel
{% else %}
User Dashboard
{% endif %}
{% else %}
Please log in.
{% endif %}If user.is_authenticated is True and user.is_admin is False, what will be rendered?
Follow the nested {% if %} conditions carefully.
The user is authenticated but not admin, so the inner {% else %} branch runs, showing User Dashboard.
Consider this template snippet:
{% if user.is_admin %}
Admin content
{% else %}
Regular content
{% endif %}If user is None, what error occurs and why?
Think about what happens when you try to access a property on None.
Accessing user.is_admin when user is None causes an AttributeError because NoneType has no such attribute.
In Flask templates, which approach best ensures unauthorized users cannot see admin-only content?
Think about where content is actually removed versus just hidden.
Using template-level {% if %} checks prevents unauthorized content from being sent to the browser, which is more secure than hiding with CSS or JavaScript. Backend checks alone are not enough if templates render all content.