Just one comment - Django lets you render to JSON just as easily as rendering to HTML (or XML). You just write your template as JSON and set the MIME type for the response accordingly. Because I control my JSON parsing on the client side, I set the MIME type to text/plain but you could set to another if you wanted.
I realise that this doesn't actually solve your problem of combining HTML and JSON in a response and I think one of the other comments addresses this but I wanted to make the point that JSON by itself is easy. Cheers Ian On Jun 16, 1:17 pm, Alex <alexle...@googlemail.com> wrote: > Hi, > > Please can anyone help with an app architecture problem I am having? > (I am quite new to Django) > > I have an app which which serves up XHR requests (via YUI3 io > uitility) to urlpatterns. The views make HttpResponses using > render_to_response like so: > > return render_to_response("registration/register.html", { > 'form': form, > }, context_instance=RequestContext(request)) > > That is all fine: The html content is rendered in the relevant div > (using a YUI3 io's success callback) . > > But the problem I have - and I may be thinking about this in the wrong > way - is that I also want to pick out some variables from the response > to use in my js success callback. If I wasn't using django templating > this could be straightforwardly achieved with a JSON response parsed > client side. So my difficulty is that I want both a rendered template > response and some JSON response in the same callback... I have thought > about 'enriching' the render_to_response context with these additional > variables, inserting them in hidden html fields and then querying the > dom for their values - but that feels awkward and also means the > response has to be added to the dom before the js can act on their > values. > > This seems like a familiar nut that must be well documented > somewhere... :) any help, pointers very appreciated. > > Thanks > Alex -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.