user592419
user592419

Reputation: 5223

Flask URL Display

I have a custom url that looks like

@app.route('/user/<user_name>/<param>')
def show_param(user_name, param):
    #do something

The page displays fine and is working well but param can have spaces, etc, in it, and I'd rather not show those. What I'd like to do is change the visual display of param before it's shown to users. How do I get access to that?

Upvotes: 1

Views: 1449

Answers (1)

rsalmond
rsalmond

Reputation: 413

You could tweak the URL to suit your taste and then redirect to that.

@app.route('/user/<user_name>/<param>')
def show_param(user_name, param):
    if ' ' in param:
        param = param.replace(' ', '-')
        return redirect(url_for('show_param'), user_name=user_name, param=param)

Upvotes: 3

Related Questions