📝 fix docs error
This commit is contained in:
parent
9b9e1c8da0
commit
c4a4f9ead3
@ -153,7 +153,7 @@ As with the `routes` argument, as many routes as you'd like can be registered he
|
||||
|
||||
## Finding Routes Again
|
||||
|
||||
> New in 1.1.0
|
||||
> New in 1.1.0!
|
||||
|
||||
If you need to find the path that's associated with a route (for example, for a RedirectResponse), you can use the `app.reverse()` function to find it. This function takes the name of the view and returns the path that it's associated with. For example:
|
||||
|
||||
@ -166,14 +166,22 @@ path = app.reverse("example")
|
||||
print(path) # -> "/example"
|
||||
```
|
||||
|
||||
If you have a route that takes arguments, you can pass them in as keyword arguments:
|
||||
If you have a route that takes arguments, you can pass them in as a dictionary:
|
||||
|
||||
```python
|
||||
@app.route("/example/<int:id>", name="example")
|
||||
def example(request, id):
|
||||
return HttpResponse(body=f"Example with id {id}")
|
||||
@app.route("/example/<int:obj_id>", name="example")
|
||||
def example(request, obj_id):
|
||||
return HttpResponse(body=f"Example with id {obj_id}")
|
||||
|
||||
path = app.reverse("example", id=3)
|
||||
path = app.reverse("example", {'obj_id': 3})
|
||||
print(path) # -> "/example/3"
|
||||
```
|
||||
|
||||
You can also provide a dictionary of query parameters to be added to the URL:
|
||||
|
||||
```python
|
||||
path = app.reverse("example", {'obj_id': 3}, query={'name': 'james'})
|
||||
print(path) # -> "/example/3?name=james"
|
||||
```
|
||||
|
||||
The arguments you pass in must match what the path expects, or you'll get a `SpiderwebException`. If there's no route with that name, you'll get a `ReverseNotFound` exception instead.
|
Loading…
Reference in New Issue
Block a user