Skip to content

Instantly share code, notes, and snippets.

@oprypin
Created March 22, 2014 09:49
Show Gist options
  • Save oprypin/1dfeb7cfbb66a7e26bab to your computer and use it in GitHub Desktop.
Save oprypin/1dfeb7cfbb66a7e26bab to your computer and use it in GitHub Desktop.
How Flask+Jinja2 templating should be done generally
<!DOCTYPE html>
<html>
<head>
{% block head %}
<title>{% block title %}Awesome website{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}"/>
{% endblock head %}
</head>
<body>
<header>
<div id="logo">
<a href="/" title="Go to home page"><img src="{{ url_for('static', filename='logo.png') }}" alt="Logo"/></a>
</div>
</header>
<main role="main">
{% block content %}
{% endblock content %}
</main>
<footer>
{% block footer %}
Copyright blah blah
{% endblock footer %}
</footer>
</body>
</html>
{% extends 'base.html' %}
{% block title %}User {{ user.name }} - {{ super() }}{% endblock %}
{% block content %}
<div>
{{ user.name }}
{% if user is sameas current_user() %}
<form action="{{ url_for('logout') }}" method="POST">
<input type="submit" value="Log out"/>
</form>
{% endif %}
</div>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment