basic example for generating Xml in Django

This is my view

def Getdata(request):
    data = serializers.serialize("xml", MessageHeaderModel2.objects.all())
    pprint.pprint(data)
    f = open('content.xml', 'w')
    myfile = File(f)
    myfile.write(data)
    myfile.close()
    return HttpResponse(data)

the output 127.0.0.1:8000 give this error

Exception Value: Expected a character buffer object

But the 'data' output in terminal gives xml output.

Why is the xml not generated in content.xml ?

Answers


I could not understand why you have this line:

myfile = File(f)

Its not a python method as far as I know. If you simply want to write the data to a file remove this line:

def Getdata(request):
    with open("file.xml", "w") as out:
        xml_serializer.serialize(MessageHeaderModel2.objects.all(), stream=out)
    data = serializers.serialize("xml", MessageHeaderModel2.objects.all())
    pprint.pprint(data)
    return HttpResponse(data)

Need Your Help

VB Net - Pass data from Thread to Main GUI

vb.net multithreading

I've managed to get the data I want in a thread, however I'm having trouble getting my head around passing the data back into my main thread (GUI).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.