How to remove parameters from URL in Flask python -


In my website I have URLs that will be backward like parameters:

  example .com / MagicPage /? P = 10 & amp; D = draft   

Is there a way to remove these parameters after the request is processed? So when the user clicks on a link, the parameters are passed, but the visible URL only example.com/magicpage

more details:

  @ app.route ("/ Magic page") DEIF Magic page (): Parameter parameters and work complete remove the indexed parameters in the URL, return to the render page    

There are two ways to do this.

Option 1: Use POST parameter instead of GET.

If the parameter adds a HTML form, method = post to and

gtc: tag, and replace your page with:
  @ app.route ("/ magic page") dig magic page (): param1 = request.args.get ("param1") param2 = request.args.get ("param2") < / Code>  

From:

  @ app.route ("/ magicpage", methods = ["post"]) DEF magic page (): param1 = request. Form.get ("param1") param2 = request.form.get ("the ultimate 2")   

There is no redirection to the top Downside is that if a user refreshes the resulting page If it tries to shut down, then it will get an unpleasant browser popup about resubmitting it:

Confirming Firefox refresh of a post webpage

He said, this is a more common way of hidden parameters passing in the web.


Option 2: After the parameters have been processed, make a redirect.

This is a bit complicated because we are redirecting to the same page, we have to check whether they are coming to this page for the first time or the other. / P>

The best way to do this is using a post request. It has the advantage of not having fresh fresh popups, but the loss of not providing the parameter in the post-rendering position until you submit it to the session.

  @ app.route ("MagicPage", methods = ["GET", "POST"]) DEF George Page (): If request.method == 'POST': # Process Parameters (Request.path) if request.method == "GET": #Render Page   

Alternatively, you simply check the appearance of a parameter as your indicator Can:

  @ app.route ("/ magicpage Def Magic page (): if = request.args.get (" param1 ", none) None: # Process Parameter Redirect (request.path) else: #Render Page    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -