Name from other page included in other page is not displayed


In my application, I would like to include the name, entered by the user, at page one, to the second page. But when I paste the jinja print "{{ data }}" to the table, the name does not appear on the second page. It works flawlessly on the first one. How can I make the name appear on both sides?
Here is my code:

class Earning(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    earning_date = db.Column(db.DateTime(),
    earning_data = db.Column(db.String())
    earning_amount = db.Column(db.Integer())
    note_id = db.Column(db.Integer, db.ForeignKey(''))
    user_id = db.Column(db.Integer, db.ForeignKey(''))

class Note(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    data = db.Column(db.String(10000))
    description = db.Column(db.String(10000))
    date = db.Column(db.Date)
    user_id = db.Column(db.Integer, db.ForeignKey(''))
    earnings = db.relationship('Earning', backref='note', lazy='select')
    spendings = db.relationship('Spending', backref='note')

creating 1st page, where user enter the name:

@views.route('/', methods=['GET', 'POST'])
def home():
    if request.method == 'POST':
        description = request.form.get('description')
        if len(note) < 1:
            flash('Nie wpisałeś żadnej treści', category='error')
            new_note = Note(description=description,, data=note,
            flash('Budżet dodany', category='success')

    return render_template("home.html", user=current_user)

creating the second page where I want to display the name entered by user at home.html:

@views.route('/earnings', methods=['GET', 'POST'])
def earnings():

    if request.method == 'POST':
        earning_data = request.form.get('earning_data')
        earning_amount = request.form.get('earning_amount')
        if len(earning_data) < 1:
            flash('Nie wpisałeś żadnej treści', category='error')
        elif len(earning_amount) < 1:
            flash('Nie wpisałeś żadnej wartości', category='error')
            earning_table = Earning(
            flash('Zarobek dodany', category='success')

    workingData = Earning.query.all()
    earning_list = []
    for sales in workingData:
        i = sales.earning_amount
    earning_list = sum(earning_list)
    return render_template('earnings.html',

and HTML which:

<main class="main">
  <div class="responsive-wrapper">
  <div class="main-header">
    <h1> <i> NAME: </i> {{ data }} </h1>

{{ data }} works fine at first page home.html, but at earnings.html is not displayed
Please help


You need to pass the variable to the the page here:

 return render_template("home.html", user=current_user)

I’m not sure where you get that variable though on that page, I can’t see it being sent. Additionally, it looks like you are validating the user input in the form that it meets a length criteria, you are better doing this using forms validation using WTF forms.

Answered By – Aristotle

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published