django 微信企业号 返回text消息

from django.template import Context,Template
textTemplate="""
        <xml>
        <ToUserName><![CDATA[{{target}}]]></ToUserName>
        <FromUserName><![CDATA[{{source}}]]></FromUserName>
        <CreateTime>{{time}}</CreateTime>
        <MsgType><![CDATA[text]]></MsgType>
        <Content><![CDATA[{% autoescape off %} {{content}} {% endautoescape %} ]]></Content>
        <MsgId>{{MsgId}}</MsgId>
        <AgentID>{{AgentID}}</AgentID>
        </xml>
    """


    def response_text(self,msg):
        """
        回复文字消息
        """
        oneDic=self.message.__dict__
        oneDic['content']=msg;
        oneDic['time']=str(int(time.time()))
        t=Template(self.textTemplate)
        c=Context(oneDic)
        rs=t.render(c)
        
        return rs

其中避免html字符串被转译

{% autoescape off %} {{content}} {% endautoescape %}

posted @ 2015-10-26 20:03  springday  阅读(436)  评论(0编辑  收藏  举报