Can I use XSLT in Django?

2019-02-19 08:49发布

We use Django for writing our new project. Our designer wants to write templates with XSLT. As you know Django has its own template system, and I don't have any arguments why the designer can't use XSLT. 2 questions:

  1. Can I return XML in my views?
  2. Is there a reason for doing this? What facts can help me changing his view on Django's templating system?

1条回答
冷血范
2楼-- · 2019-02-19 08:58

1). Yes, why not.

import libxslt
import libxml2

from django http import HttpResponse

def your_view(request):
    xsl = libxslt.parseStyleSheetDoc(libxml2.parseFile('stylesheet.xml'))
    data = # your xml here
    result = xsl.applyStylesheet(data)
    response = HttpResponse()
    xsl.saveResultToFile(response, result)
    return response

2). This will likely solicit opinion, debate, arguments, polling, or extended discussion. :-)

查看更多
登录 后发表回答