pythonflask

Flask: Is it possible to Mask a URL with variables?


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)

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

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


Solution

  • I was able to achieve my goal using:

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

    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.

    Thanks all for your time