mirror of https://github.com/encode/starlette.git
Add name to app routes (#205)
* Version 0.8.2 * Add name argument to app.route(...)
This commit is contained in:
parent
8e30f073f0
commit
ce62bdfa51
|
@ -1,3 +1,9 @@
|
|||
## 0.8.2
|
||||
|
||||
## StaticFiles
|
||||
|
||||
* StaticFiles no longer reads the file for responses to `HEAD` requests.
|
||||
|
||||
## 0.8.1
|
||||
|
||||
## Templating
|
||||
|
|
|
@ -17,6 +17,7 @@ find starlette -type d -name __pycache__ -delete
|
|||
|
||||
${PREFIX}python setup.py sdist
|
||||
${PREFIX}twine upload dist/*
|
||||
${PREFIX}mkdocs gh-deploy
|
||||
|
||||
echo "You probably want to also tag the version now:"
|
||||
echo "git tag -a ${VERSION} -m 'version ${VERSION}'"
|
||||
|
|
|
@ -1 +1 @@
|
|||
__version__ = "0.8.1"
|
||||
__version__ = "0.8.2"
|
||||
|
|
|
@ -92,12 +92,15 @@ class Starlette:
|
|||
path: str,
|
||||
route: typing.Callable,
|
||||
methods: typing.List[str] = None,
|
||||
name: str = None,
|
||||
include_in_schema: bool = True,
|
||||
) -> None:
|
||||
self.router.add_route(path, route, methods=methods)
|
||||
self.router.add_route(path, route, methods=methods, name=name)
|
||||
|
||||
def add_websocket_route(self, path: str, route: typing.Callable) -> None:
|
||||
self.router.add_websocket_route(path, route)
|
||||
def add_websocket_route(
|
||||
self, path: str, route: typing.Callable, name: str = None
|
||||
) -> None:
|
||||
self.router.add_websocket_route(path, route, name=name)
|
||||
|
||||
def exception_handler(
|
||||
self, exc_class_or_status_code: typing.Union[int, typing.Type[Exception]]
|
||||
|
@ -112,19 +115,24 @@ class Starlette:
|
|||
self,
|
||||
path: str,
|
||||
methods: typing.List[str] = None,
|
||||
name: str = None,
|
||||
include_in_schema: bool = True,
|
||||
) -> typing.Callable:
|
||||
def decorator(func: typing.Callable) -> typing.Callable:
|
||||
self.router.add_route(
|
||||
path, func, methods=methods, include_in_schema=include_in_schema
|
||||
path,
|
||||
func,
|
||||
methods=methods,
|
||||
name=name,
|
||||
include_in_schema=include_in_schema,
|
||||
)
|
||||
return func
|
||||
|
||||
return decorator
|
||||
|
||||
def websocket_route(self, path: str) -> typing.Callable:
|
||||
def websocket_route(self, path: str, name: str = None) -> typing.Callable:
|
||||
def decorator(func: typing.Callable) -> typing.Callable:
|
||||
self.router.add_websocket_route(path, func)
|
||||
self.router.add_websocket_route(path, func, name=name)
|
||||
return func
|
||||
|
||||
return decorator
|
||||
|
|
|
@ -295,37 +295,46 @@ class Router:
|
|||
path: str,
|
||||
endpoint: typing.Callable,
|
||||
methods: typing.List[str] = None,
|
||||
name: str = None,
|
||||
include_in_schema: bool = True,
|
||||
) -> None:
|
||||
route = Route(
|
||||
path,
|
||||
endpoint=endpoint,
|
||||
methods=methods,
|
||||
name=name,
|
||||
include_in_schema=include_in_schema,
|
||||
)
|
||||
self.routes.append(route)
|
||||
|
||||
def add_websocket_route(self, path: str, endpoint: typing.Callable) -> None:
|
||||
route = WebSocketRoute(path, endpoint=endpoint)
|
||||
def add_websocket_route(
|
||||
self, path: str, endpoint: typing.Callable, name: str = None
|
||||
) -> None:
|
||||
route = WebSocketRoute(path, endpoint=endpoint, name=name)
|
||||
self.routes.append(route)
|
||||
|
||||
def route(
|
||||
self,
|
||||
path: str,
|
||||
methods: typing.List[str] = None,
|
||||
name: str = None,
|
||||
include_in_schema: bool = True,
|
||||
) -> typing.Callable:
|
||||
def decorator(func: typing.Callable) -> typing.Callable:
|
||||
self.add_route(
|
||||
path, func, methods=methods, include_in_schema=include_in_schema
|
||||
path,
|
||||
func,
|
||||
methods=methods,
|
||||
name=name,
|
||||
include_in_schema=include_in_schema,
|
||||
)
|
||||
return func
|
||||
|
||||
return decorator
|
||||
|
||||
def websocket_route(self, path: str) -> typing.Callable:
|
||||
def websocket_route(self, path: str, name: str = None) -> typing.Callable:
|
||||
def decorator(func: typing.Callable) -> typing.Callable:
|
||||
self.add_websocket_route(path, func)
|
||||
self.add_websocket_route(path, func, name=name)
|
||||
return func
|
||||
|
||||
return decorator
|
||||
|
|
Loading…
Reference in New Issue