小编aph*_*hex的帖子

如何在Python中使用XSLT转换XML文件?

美好的一天!需要在Python中使用xslt转换xml.我在php中有一个示例代码.

如何在Python中实现这一点或在哪里找到类似的东西?谢谢!

$xmlFileName = dirname(__FILE__)."example.fb2";
$xml = new DOMDocument();
$xml->load($xmlFileName);

$xslFileName = dirname(__FILE__)."example.xsl";
$xsl = new DOMDocument;
$xsl->load($xslFileName);

// Configure the transformer
$proc = new XSLTProcessor();
$proc->importStyleSheet($xsl); // attach the xsl rules
echo $proc->transformToXML($xml);
Run Code Online (Sandbox Code Playgroud)

python xml xslt converter

61
推荐指数
2
解决办法
6万
查看次数

启动py.test后,在读取请求的数据流后无法访问正文

下午好.

我正在使用pytest测试基于django-rest-framework的api.我有以下方法创建一个新对象(从这里采取的方法):

class JSONResponse(HttpResponse):
    """
    An HttpResponse that renders its content into JSON.
    """

    def __init__(self, data, **kwargs):
        content = JSONRenderer().render(data)
        kwargs['content_type'] = 'application/json'
        super(JSONResponse, self).__init__(content, **kwargs)


@csrf_exempt
@api_view(('POST',))
@permission_classes((IsAuthenticated, ))
def create_transaction(request):
    """
    The method takes the data in JSON-format.
    If the data is correct Transaction object will created, otherwise it returns an error also in JSON-format.
    """

    stream = StringIO('[' + request.raw_post_data + ']')
    data = JSONParser().parse(stream)
    serializer = NewTransactionSerializer(data=data, many=True)
    if serializer.is_valid():
        serializer.save()
        return JSONResponse(serializer.data, …
Run Code Online (Sandbox Code Playgroud)

python django http-post pytest django-rest-framework

5
推荐指数
1
解决办法
5309
查看次数