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.
JavaScript
x
2
1
<a href="{{ url_for('views.add_budget') }}">{{ budget.data }}</a>
2
JavaScript
1
8
1
@views.route('/add_budget', methods=['GET', 'POST'])
2
@login_required
3
def add_budget():
4
if request.method == 'POST':
5
return redirect(url_for('views.home'))
6
7
return render_template('add_budget.html', user=current_user)
8
I want heading from /add_budget page to be inherit from budget name defined by user
JavaScript
1
5
1
{% for budget in user.budgets %}
2
<br>
3
<h1>{{ budget.data }}</h1>
4
{% endfor %}
5
JavaScript
1
12
12
1
<p align="left">Name your budget:</p>
2
<br>
3
<ul class="list-group list-group-flush" id="budgets">
4
{% for budget in user.budgets %}
5
<li class="list-group-item">
6
<a href="{{ url_for('views.add_budget') }}">{{ budget.data }}</a>
7
<button type="button" class="close" onClick="deleteBudget({{ budget.id }})">
8
<span aria-hidden="true">×</span>
9
</button>
10
</li>
11
{% endfor %}
12
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:
JavaScript
1
4
1
@views.route('/add_budget/<data>', methods=['GET', 'POST'])
2
@login_required
3
return render_template('add_budget.html', data=data, user=current_user)
4
JavaScript
1
2
1
{{ data }}
2