Created
October 22, 2017 00:15
-
-
Save FreeMasen/95a3e8d8d38842f9676a0e3332c8dddd to your computer and use it in GitHub Desktop.
jinja example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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