参照:http://www.runoob.com/django/django-form.html
做了个表单提交和回显,但是报了以上错误
查资料发现是 python从request取值的是unicode码,需要转成当前文档的编码才能拼接
# -*- coding:utf-8 -*-
from django.http import HttpResponse
from django.shortcuts import render_to_response
def search_form(request):
return render_to_response('search_form.html')
def search(request):
request.encoding='utf-8'
if 'q' in request.GET:
message = '你搜索的是:'+request.GET['q'].encode('utf-8')
else:
message ='你提交空表单'
return HttpResponse(message)