Skip to content

Instantly share code, notes, and snippets.

@FreeMasen
Created October 22, 2017 00:15
Show Gist options
  • Save FreeMasen/95a3e8d8d38842f9676a0e3332c8dddd to your computer and use it in GitHub Desktop.
Save FreeMasen/95a3e8d8d38842f9676a0e3332c8dddd to your computer and use it in GitHub Desktop.
jinja example
from flask import Flask, render_template, request
from src import database
app = Flask()
@app.route('/userBooks')
def user_books():
#somehow get the username you might want to use the flask session?
#this example is going ot assume that this route is a post request
#with a form data
username = request.form.get('username')
#once you have the username you can get your list of books
#for this user
books = database.get_books(username)
#now send the books as a template argument
return render_template('userbooks.html', books=books)
<html>
<head>
</head>
<body>
{% for book in books %}
<div class="book">
<span class="book-title">{{book.title}}</span>
<span class="book-desc">{{book.description</span>
</div>
{% endfor %}
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment