I’m planning to do the 19.06.0 release on Sunday 2019/06/16 US Central time. Please let me know if you have issues you want to see resolved before that release and a brief justification. We’ve made a lot of progress on getting organized in the last 8 months, but it’s probably time to push towards noting focus issues that we can/should prioritize.
from sanic import Sanic
from sanic.request import Request
from sanic.response import json
class MyRequest(Request):
@property
def single_args(self):
"""只取第一个值作为值"""
return {k: v[0] for k, v in self.args.items()}
app = Sanic(__name__, log_config={}, request_class=MyRequest)
@app.route("/")
async def index(request):
print(request.single_args)
return json({"data": "hello"})
I create a sanic app by passing request_class=MyRequest(which achieves request.user , request.single_args etc.), but in ASGI mode, it doesn’t work, and I get a simple exception says:
ERROR: 'Request' object has no attribute 'single_args'
Traceback (most recent call last):
File "/Users/zinklu/myproject/sanic/lib/python3.7/site-packages/sanic/app.py", line 942, in handle_request
response = await response
File "./cat_and_dog/__init__.py", line 95, in wait_a_minute
print(request.single_args)
AttributeError: 'Request' object has no attribute 'single_args'
I found this in asgi.py. It always make sanic.request.Request as app’s request. shoud we change Request into sanic_app.request_class?