我正在尝试理解Python并传递变量。我正试图传递一个“行动”的身份证。我可以创建动作并看到它在那里,但我不明白如何获取id并将其从一种形式传递到另一种形式。如果有人能指出我正确的方向会很棒。
Views.py
#g.user.nickname passes in the nickname for a refernce
@app.route('/edit', methods=['GET', 'POST'])
@login_required
def edit():
form = EditForm(g.user.nickname)
if form.validate_on_submit():
g.user.nickname = form.nickname.data
g.user.about_me = form.about_me.data
db.session.add(g.user)
db.session.commit()
flash('Your changes have been saved.')
return redirect(url_for('edit'))
elif request.method != "POST":
form.nickname.data = g.user.nickname
form.about_me.data = g.user.about_me
return render_template('edit.html', form=form)
#Don't understand how to create a variable to pass a reference from post.html
@app.route('/action_request', methods=['GET', 'POST'])
@login_required
def action_requests():
form = EditReqForm()
return render_template('action_request.html',
form=form)
Post.html
<table class="table table-hover">
<tr>
<td>
<p>Raised by <a href="{{ url_for('user', nickname=action.author.nickname) }}">{{ action.raised_by }} </a>on
{{ action.date_raised.strftime('%d-%m-%Y') }}:</p>
#Trying to generate reference of action id to pass to ActionReqForm
<p><a href="{{ url_for('action_requests', id=action.id)}}"><strong>
Issue:</strong>{{
action.issue }}</a></p>
<p><strong>Source: {{action.id}}</strong>{{ action.source }}</p>
<p><strong>Immediate Action: </strong>{{ action.immediate_action }}</p>
</td>
</tr>
</table>
答案 0 :(得分:0)
找出解决方案, request.args.get()