Eugene Morozov <[EMAIL PROTECTED]> writes: > On 11 май, 13:23, Nic James Ferrier <[EMAIL PROTECTED]> > wrote: >> def user_alerts(request, user_name): >> me = get_object_or_404(User, username=user_name) >> alerts = Alert.objects.filter(user=me, seen=False) >> return tfxslt.send_json(HttpResponse(), >> { "div": >> [ { "abbr": >> { "@title": alert.created, >> "span": alert.message }} for alert in >> alerts]}, >> xslt="user_alerts") >> > > Sorry, I don't get the point. I think that XSLT is a way to separate > presentation from data. But your json looks like some kind of HTML. I > don't understand how this is better than existing Django templates.
It has several advantages: - there is proper separation between data and style, my JSON doesn't include any stylistic information, only stuff that describes the data - the JSON template *is* python, you can pretty much do anything with it: you can separate bits of the rendering with different methods, you can test it outside of Django, you can pass it around and process it with Python quite naturally. - you get JSON output if you want it, direct from your view - you get to use XSLT to turn the JSON into anything you want... you need Atom from a resource as well as HTML? Just have 2 different stylesheets but the same JSON. The way I tend to use the templates is to output POSH (Plain Old Semantic HTML) like JSON which will be transformed by XSLT into display HTML/XHTML but you don't have to do it that way... the JSON could be any old thing. I find it simpler to use POSH because I can mock up the POSH outside of a programming language. I can even get designers to template the POSH which they will then transform with XSLT. > I know and use XSLT but usually for converting between different XML > formats. XSLT works very well as a dynamic transformation language. It is very fast indeed and you can do so much with it. I don't understand why anyone would want to use these hobbled little template languages inside things like Django and Rails. -- Nic Ferrier http://www.tapsellferrier.co.uk --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---