码迷,mamicode.com
首页 > 其他好文 > 详细

Django 打印

时间:2014-10-10 13:17:54      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:http   os   ar   strong   sp   div   问题   on   代码   

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。

Django 打印

标签:http   os   ar   strong   sp   div   问题   on   代码   

原文地址:http://www.cnblogs.com/nigang/p/4015231.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!