Skip to content
Advertisement

Inheriting name of category in Flask

I am working on budget app in Flask.

Homepage give you ability to create names of Budgets and then names are transformed to links href which transfer you to another page with budget details.

<a href="{{ url_for('views.add_budget') }}">{{ budget.data }}</a>
@views.route('/add_budget', methods=['GET', 'POST'])
@login_required
def add_budget():
    if request.method == 'POST':
        return redirect(url_for('views.home'))

    return render_template('add_budget.html', user=current_user)

I want heading from /add_budget page to be inherit from budget name defined by user

{% for budget in user.budgets %}
    <br>
            <h1>{{ budget.data }}</h1>
            {% endfor %}
 <p align="left">Name your budget:</p>
  <br>
<ul class="list-group list-group-flush" id="budgets">
  {% for budget in user.budgets %}
  <li class="list-group-item">
      <a href="{{ url_for('views.add_budget') }}">{{ budget.data }}</a> 
      <button type="button" class="close" onClick="deleteBudget({{ budget.id }})">
      <span aria-hidden="true">&times;</span>
    </button>
  </li>
  {% endfor %}

and it works fine until I add second budget – in that case heading on specific budget page inherit both budget names. When I add three – it inherit three, and so on.

Is that away in Flask to make the heading inherit only one defined by user text?

Advertisement

Answer

I have found resolution:

@views.route('/add_budget/<data>', methods=['GET', 'POST'])
@login_required
return render_template('add_budget.html', data=data, user=current_user)
{{ data }}
8 People found this is helpful
Advertisement