Flask:是否可以使用变量屏蔽网址? [英] Flask: Is it possible to Mask a URL with variables?

查看:59
本文介绍了Flask:是否可以使用变量屏蔽网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将变量从一个站点传递到另一个站点.没问题,因为有很多方法可以做到.不过,我在如何隐藏" URL中的这些变量的同时却仍在努力获取值.前任.:如果我使用"request.args.get":

I want to pass variables from a site to another. This is no problem, as there are many ways to do it. I'm struggling though, in how I can 'hide' these variables in the URL, and yet be able to get the values. Ex.: If I use 'request.args.get':

@page.route('/users', methods=['GET', 'POST'])
def users():
    user = request.args.get('user')
    return render_template('users.html', user=user)

当我单击链接时,生成的URL是: http://localhost:5000/users?user = john

When I click in the link, the URL generated is: http://localhost:5000/users?user=john

我的目标是访问约翰"部分的用户"页面,但是用户在URL路径中看到的只是 http://localhost:5000/users

My goal is to access the 'users' page, in the 'John' section, but what the user will see in the URL path is only http://localhost:5000/users

推荐答案

我能够使用以下方法实现目标:

I was able to achieve my goal using:

window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", "/users/");

我不是Web开发人员,只是Python/Flask爱好者,并且知道"window.history.pushState()"是用于其他目的的.我也知道它是HTML5功能,并非所有浏览器都兼容.但是,嘿,它成功了;).

I'm no Web Dev'er, just a Python/Flask enthusiast and know that 'window.history.pushState()' is meant for other purposes. I'm also aware that it a HTML5 Feature and not all browsers are compatible. But hey, it did the trick ;) .

除非有人指出我不应该使用这种方法的原因,否则这是我的解决方案.

Unless someone point out reasons I shouldn't be using this approach, this is my solution.

感谢您的时间

这篇关于Flask:是否可以使用变量屏蔽网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆