Django 打印

fentin 发表于 2008-07-28 17:52:44

请教Django Python中文问题

用django写一个往打印机里面写东西的程序,
需要往打印机里面写gb2312编码的中文和英文还有数字
在Python中已经能打印,但是中文为乱马,在django中因为编码问题一直报错.
谢谢:)

代码如下:
import os
a = '你好python'
c =  "echo %s > /dev/usb/lp0"  % a
os.system(c)

django中:

import os
from django.http import HttpResponse
def print_it(request):
    if request.POST:
        a = request.POST['pstr']
        c = "echo '%s' > /dev/usb/lp0" % a
        os.system(c)

fentin 发表于 2008-07-28 18:26:37

 

我的os 是Ubuntu阿

fentin 发表于 2008-07-28 19:06:17

 

问题已解决:0
:mrgreen: 

解决方法:

a.decode("UTF-8").encode("GBK")

2gua 发表于 2008-07-28 20:05:35

 

不太用Django。
原文地址:https://www.cnblogs.com/nigang/p/4015231.html