Skip to content

Instantly share code, notes, and snippets.

@kaniket7209
Created December 2, 2021 06:00
Show Gist options
  • Save kaniket7209/36addea51f69ae742cce6d84e48d0123 to your computer and use it in GitHub Desktop.
Save kaniket7209/36addea51f69ae742cce6d84e48d0123 to your computer and use it in GitHub Desktop.
Jinja2 Expressions
1. What is the use of {%...%} delimiter ?
Answer: It is used for the statements of the Jinja language that do not have an output.
2. What is the use of {{...}} delimiter ?
Answer: It is the used to print the content in between the curly brackets to the template output.
3. What are the Math Expressions that we can use here
Answer: + Addition -> eg 20 + 30 returns 50
- Subtraction. -> eg 20 - 10 returns 10
* Multiplication. -> eg 2 * 3 returns 6
/ Division. -> eg 10 / 5 returns 2
// Returns integer result of division rounded down, e.g. 20 // 7 returns 2.
% Calculate the remainder of division. For instance, 11 % 7 returns 4.
4. Why can't we use ** power operand in jinja2 expressions?
Answer: This is because the math expression of a power operand ** is not supported. e.g. {{ 2 ** 16 }} would not work.
1. What is the symbol that we can use to interpolate expressions
a) []
b) {}
c) ()
d) None of teh above
Answer: b) {}
2. What is the correct syntax to interpolate exprrssions
a) {{ variable }}
b) { variable }
c) {% variable %}
d) {{% variable %}}
Answer: a) {{ variable }}
3. What is the correct syntax to perform addition in jinja2
a) {{a}} + {{b}}
b) {{ a+b }}
c) { a } + { b }
d) Both a and b
Answer: b) {{ a+b }}
4. What is the correct syntax to perform string concatenation using Jinja2
a) {{ A + B }}
b) {{ A }} {{ B }}
c) {{A}},{{B}}
d) Both a and b
Answer: d) Both a and b
5. Suppose we have added "/" at end in convention such as @app.route("/home/").
So, can we access the domain by writting http://127.0.0.1:5000/home
a) Yes
b) No
Answer: Yes
6. Suppose we have a convention as @app.route("/home")
Ao, can we access the domain by writting http://127.0.0.1:5000/home/
a) Yes
b) No
Answer: No
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment