简体   繁体   English

在Python,Flask中传递变量

[英]Passing Variables in Python, Flask

I am trying to understand Python and passing variables. 我试图了解Python并传递变量。 I am trying to pass an id for an 'action'. 我正在尝试传递“操作”的ID。 I can create the action and see the is there but I do not understand how to take the id and pass it from one form to another. 我可以创建操作并查看其中的内容,但不了解如何获取ID并将其从一种形式传递给另一种形式。 If anyone could point me in the right direction would be great. 如果有人能指出我正确的方向,那就太好了。

Views.py 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 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>

找出解决方案request.args.get()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM