Skip to content

Instantly share code, notes, and snippets.

View kaustubhgupta's full-sized avatar
🎯
Brewing Fresh Articles

Kaustubh Gupta kaustubhgupta

🎯
Brewing Fresh Articles
View GitHub Profile
from flask import Flask, render_template
app = Flask(__name__)
app.jinja_env.add_extension('jinja2.ext.loopcontrols')
@app.route('/', methods=['GET', 'POST'])
def index():
return render_template('new.html',
)
{% set users = ['Kaustubh', 'Saksham', 'Saumya', 'Ayushi', 'Abhishek', 'Anmol'] %}
{% import "helper.html" as helpers %}
{{helpers.generateList(users)}}
{% macro generateList(input_list)%}
<ul>
{% for i in input_list %}
<li>{{i}}</li>
{% endfor %}
</ul>
{% endmacro %}
{% set links %}
<li><a href="/">Index</a>
<li><a href="/blogs">Blogs</a>
<li><a href="/about">About</a>
<li><a href="/work">Work</a>
{% endset %}
{% set users = ['Kaustubh', 'Saksham', 'Saumya', 'Ayushi', 'Abhishek', 'Anmol'] %}
{% macro generateList(input_list)%}
<ul>
{% for i in input_list %}
<li>{{i}}</li>
{% endfor %}
</ul>
{% endmacro %}
{% extends "base.html" %}
{% block title %}This is the child page{% endblock %}
{% block content %}
<h1>This is the child page</h1>
<p class="important">
The content here is from the child template
</p>
{% endblock %}
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}{% endblock %} - My Webpage</title>
</head>
<body>
<h3>This will come up in every Webpage (Base template)</h3>
<div id="content">{% block content %}{% endblock %}</div>
<div id="footer">
This content is from base template
{% macro generateList(input_list)%}
<ul>
{% for i in input_list %}
<li>{{i}}</li>
{% endfor %}
</ul>
{% endmacro %}
{{generateList(users)}}
{% for i in <iterable_object> %}
{% if <condition> %}
{# the if part #}
{% elif <condition> %}
{# the elif part #}
{% else %}
{# the else part #}
{% endif %}
{% endfor %}
{% for i in <iteratable_object> %}
{# operations to perform #}
{% endfor %}