简体   繁体   English

Flask render_template上下文未显示在URL中

[英]Flask render_template context not showing in URL

I am trying to pass params to the URL in flask, but I can not get them to show up for anything. 我正在尝试将参数传递给flask中的URL,但是我无法让它们显示任何内容。

@logout.route('/logout')
def logout_page():
    current_provider = current_oauth_user.get_provider()
    return render_template('index.html', provider=current_provider)

I expect to see /logout?provider=facebook but I just get /logout 我希望看到/logout?provider=facebook但我刚得到/logout

Right now I am doing this: 现在我正在这样做:

@logout.route('/logout')
def logout_page():
    provider = request.args.get('provider')
    current_provider = current_oauth_user.get_provider()
    if not provider and current_provider:
        return redirect(url_for('logout.logout_page',
                                provider=current_provider))
    return render_template('index.html')

but that just seems so terrible. 但这似乎太可怕了。

You should return some value using '/logout' path. 您应该使用'/ logout'路径返回一些值。 So at first, you use render_template(index.html) under def main() . 因此,首先,您可以在def main()下使用render_template(index.html) def main() Then you create def logout_page() and return some value ( in your case is current_provider ). 然后,创建def logout_page()并返回一些值(在您的情况下为current_provider )。

@app.route('/')
def main():
    return render_template('index.html')

@app.route('/logout')
def logout_page():
    current_provider = current_oauth_user.get_provider()
    return current_provider

if __name__=="__main__":
    app.run(port=8000)

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

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