Keon Kim
Keon Kim

Reputation: 760

is this approach to Flask routing reasonable?

I am making every path lead to index.html, since it is a single page app. I made a blueprint called mod and put all the restul api there using flask-restful

@mod.route('/')
@mod.route('/<path:p>')
def home(p=0):
    return render_template('index.html')

is this right way to do it? I am little concerned about p=0 part. the variable p is never used, but has to be there since it has to receive path variable p

Upvotes: 0

Views: 119

Answers (1)

Carson Crane
Carson Crane

Reputation: 1207

Your routing is certainly reasonable.

A more simple/readible way of doing it might be:

@mod.route('/')
@mod.route('/<path>')
def home(*args, **kwargs):
    return render_template('index.html')

From an efficiency standpoint its probably better to handle this entirely on the webserver (nginx/apache/whatever).

Upvotes: 2

Related Questions