参照: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)

 

相关文章:

  • 2022-12-23
  • 2022-01-05
  • 2022-12-23
  • 2021-12-05
  • 2021-06-06
  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-05
  • 2021-07-24
  • 2021-05-10
  • 2021-08-01
  • 2022-12-23
相关资源
相似解决方案