I am trying to create a journal app in Python Flask. I am stuck trying to send different data to my functions. It is hard to describe without showing you the code so I will post that below then continue.
from flask import Flask, render_template
app = Flask(__name__)
entries = [
{
'entry_number': 1,
'author': 'X',
'title': 'First Post',
'date_written': 'January 1st, 2019',
'content': 'First journal entry.'
},
{
'entry_number': 2,
'author': 'X',
'title': 'Second Post',
'date_written': 'January 1st, 2019',
'content': 'Second journal entry.'
}
]
@app.route('/')
def home():
return render_template('home.html')
@app.route('/entryone')
def entry_one(entry):
return render_template('journal_entry.html', post=entry)
@app.route('/entrytwo')
def entry_two():
return render_template('journal_entry.html', entries=entries)
for post in entries:
if post['entry_number'] == 1:
entry_one(post)
if __name__ == '__main__':
app.run()
What I am trying to do is send the data from my list of dictionaries to corresponding functions below. So the dictionary with entry_number 1 would have the data for the entryone function. And the dictionary with the entry number 2 would have the data for entrytwo and so on.
I try to do this and the code breaks. This is probably not the best way to do this to begin with, but I still need to fix it. Does anyone know the proper way to send the right dictionary data to the right function?