python - The view app.views.model didn't return an HttpResponse object -
this views.py file. on way generate xml file, data getting mysql. first time working make changes cant remember did s not working ...
in views.py
def messageheadermodel2(request): if request.method == "post": form = messageheaderform(request.post) if form.is_valid(): ddex_party_id = request.post.get('ddex_party_id',none) data = serializers.serialize("xml", messageheadermodel2.objects.all()) open("file.xml", "w") out: xml_serializer.serialize(messageheadermodel2.obj ects.all(), stream=out)
the error gettin
>exception type:valueerror exception value:the view app.views.messageheadermodel2 didn't return httpresponse object.
you in fact not returning httpresponse
object!
django views must return instance of httpresponse
@ end of view:
from django.http import httpresponse def view(request): ... return httpresponse("the page content")
you can return may other subclasses of httpresponse
, see documentation list.
you can use of shortcut functions render page using django templating system, again documentation helpful here, briefly:
from django.shortcuts import render_to_response def view(request): ... return render_to_response('my_template.html', my_data_dictionary, context_instance=requestcontext(request))
a complete example using code above:
def view(request): if request.method == "post": form = messageheaderform(request.post) if form.is_valid(): ddex_party_id = request.post.get('ddex_party_id',none) data = serializers.serialize("xml", messageheadermodel2.objects.all()) open("file.xml", "w") out: out.write(data) return httpresponse(data) else: # return error response? return httpresponsenotallowed(['post'])
Comments
Post a Comment