Sunday, January 29, 2012

Re: Is it possible to return an HttpResponse in django with text & a json object?

To do this use serializers or you need to make it a plain text iterate
over objects and make it a string and return httpresponse as a text.

On Jan 29, 7:24 pm, CareerDhaba tech <t...@careerdhaba.com> wrote:
> Hi all,
>
> I am in a bit of a jiffy and need some guidance. Here is the issue:
>
> I am creating a basic Q&A application, where a question pops up for the
> user, along with a form to submit the answer. Depending on the type of
> question, the input of  the form changes (ie if its a multiple choice, its
> radio buttons, but if its a word problem, its a text area). I am doing this
> by extending the ModelForm's __init__ method. So far, so good.
>
> The problem occurs when an answer is submitted via jquery ajax. My view
> function receives and processes the request correctly, but I am unable to
> figure out how to send back *both *the question object (as json object) and
> the form object (as html) via HTTPResponse. I would be processing the data
> sent to the client via jquery.
>
> I have posted this on SO, but the suggested answer doesn't make sense to
> me. Here's the link:http://bit.ly/wGkZdA
>
> A part of me feels that there is potentially another cleaner way to do what
> I am trying to do, but I have yet to come up with a more elegant solution
> (or any solution for that matter).
>
> My views.py code is on the SO link, or you can also find it here:http://dpaste.com/hold/694698/
>
> Thanks in advance for all your help.
>
> Best,
> Harshil

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment