error source code:
#Receive request data
def search(request):
request.encoding = 'utf-8'
if 'q' in request.GET:
message = 'You searched for: ' +request.GET['q'].encode('utf-8')
else:
message = 'You submitted an empty form'
return HttpResponse(message)
code marked red position, we can see that encode function is used to transcode, because encode transcode returns data of type Bytes, can not be directly added with data of type STR.
Since the request request has been transcoded in the first sentence of the function, we remove the following encode function here, and the error can be solved.
The updated code is:
#Receive request data
def search(request):
request.encoding = 'utf-8'
if 'q' in request.GET:
message = 'You searched for: ' +request.GET['q']
else:
message = 'You submitted an empty form'
return HttpResponse(message)
Similar Posts:
- Ajax submitting datagram in firebox_ ERROR_ DOCUMENT_ NOT_ Cached error
- Spring MVC upload file error string cannot be converted to multipartfile
- [Solved] Content type ‘application/x-www-form-urlencoded;charset=UTF-8’ not supported
- HTTP status 405 – request method ‘get’ not supported using springmvc
- [Django CSRF tutorial] solve the problem of forbidden (403) CSRF verification failed. Request aborted
- Postman reported an error unsupported media type [How to Solve]
- Hyperf captures PHP error levels, such as notice, warning and error, and returns them to the front-end
- [Solved] Uncaught TypeError: Cannot create property ‘LAY_TABLE_INDEX’ on number ‘1’
- Error reporting and resolution of Python 3 using binascii method
- Uncaught typeerror: the solution of illegal invocation problem