-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
Closed as not planned
Description
I think it would be cool if there were built-in aliases for routes, for example:
@route(
"/information",
aliases=["/info", "/faq"] # <- They all show the same thing as the main route `/information`.
)It might be useless to some, but I don't. I think it would be useful to allow people to define multiple aliases for one route. It is possible as of now using this code I made:
from typing import List, Callable, Union
from flask import Flask, wraps, redirect, jsonify
app = Flask(__name__)
def route(name: str, aliases: List[str] = [], **options) -> Callable:
def decorator(func: Callable) -> Callable:
@app.route(name, **options)
@wraps(func)
async def wrapper(*args, **kwargs) -> Union[redirect, jsonify]:
return await func(*args, **kwargs)
[app.route(alias, **options)(wrapper) for alias in aliases]
return wrapper
return decoratorReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels