python报错:Exception Value:can only concatenate str (not "bytes") to str

The source code is given:

# Receiving request data 
DEF Search (Request): 
    request.encoding = ' UTF-. 8 ' 
    IF  ' Q '  in `` request.GET``: 
        Message = ' what you search for: ' + `` request.GET`` [ ' Q ' .] Encode ( 'UTF-8')
     the else : 
        the Message = ' you have submitted an empty form ' 
    return HttpResponse (the Message)

Code Red winning position can be seen using a function encode transcoding, because transcoding encode return data type is bytes, and can not be added directly str types of data .

Since the first sentence has to request transcoding function request, so here we will be back encode function removed, the error can be solved.

The updated code is:

# Receiving request data 
DEF Search (Request): 
    request.encoding = ' UTF-. 8 ' 
    IF  ' Q '  in `` request.GET``: 
        Message = ' what you search for: ' + `` request.GET`` [ ' Q ' ]
     the else : 
        Message = ' you have submitted an empty form ' 
    return HttpResponse (the Message)

 

Guess you like

Origin www.cnblogs.com/wyhluckdog/p/11362094.html