fix SERVER_NAME enforcement in url_for and request.args documentation (#1708)

* 🐛 fix SERVER_NAME enforcement in url_for

fixes #1707

* 💡 add additional documentation for using request.args

fixes #1704

*  add additional test to check url_for without SERVER_NAME

* 📝 add changelog for fixes
This commit is contained in:
Harsha Narayana
2019-11-01 23:02:49 +05:30
committed by 7
parent e506c89304
commit e81a8ce073
5 changed files with 43 additions and 5 deletions

View File

@@ -204,9 +204,8 @@ The output will be:
## Accessing values using `get` and `getlist`
The request properties which return a dictionary actually return a subclass of
`dict` called `RequestParameters`. The key difference when using this object is
the distinction between the `get` and `getlist` methods.
The `request.args` returns a subclass of `dict` called `RequestParameters`.
The key difference when using this object is the distinction between the `get` and `getlist` methods.
- `get(key, default=None)` operates as normal, except that when the value of
the given key is a list, *only the first item is returned*.
@@ -223,6 +222,19 @@ args.get('titles') # => 'Post 1'
args.getlist('titles') # => ['Post 1', 'Post 2']
```
```python
from sanic import Sanic
from sanic.response import json
app = Sanic(name="example")
@app.route("/")
def get_handler(request):
return json({
"p1": request.args.getlist("p1")
})
```
## Accessing the handler name with the request.endpoint attribute
The `request.endpoint` attribute holds the handler's name. For instance, the below