I have a database with table page that has attributes url and referrer (among other ones). I want to make a function that returns those two attributes and prints them in a table in the browser.
This is my function:
@route ('/pages_url', method = 'GET')
@view('pages')
def all_pages():
c.execute("select url from page")
pages_url = c.fetchall()
c.execute("select referrer from page")
pages_referrer = c.fetchall()
pages_dict = dict(zip(pages_url, pages_referrer))
return pages_dict
and this is my template:
<html>
<body>
<table>
% for key, value in pages_dict.iteritems():
<tr>
<td>{{key.title().strip()}}</td>
<td>{{value.title().strip()}}</td>
</tr>
% end
</table>
</body>
</html>
I know the function is a bit messy but I don't know how select url, referrer from page
would be returned and how it would work
Aucun commentaire:
Enregistrer un commentaire