On Tuesday, 2 June 2015 19:06:35 UTC+2, Carl Meyer wrote: > > On 06/02/2015 05:54 AM, Aymeric Augustin wrote: >
> Using Jinja2 on the server and nunjucks on the client with shared > templates works very well, is quite easy, and doesn't require Node.js on > the server. I've been using this combination for a year and a half on > several different projects and am quite happy with it. > I'm very happy to hear that this works in production. I picked nunjucks as an example just based on reading about it, but now I know that this is something that actually works. Thanks for that! The primary discipline involved is ensuring that you only pass > JSON-serializable objects to your templates (this is required for any > template-sharing technique). In practice, this just means you need a > full set of serializers and to use them consistently. The same > serializers should be used in your server-side views and in your API, so > the objects passed to your templates on the server and client side are > the same. (I think using serializers and avoiding passing model > instances/querysets directly into template contexts is a good practice > anyway.) > I would love to see some code here if you have it available? How do you pass the JSON and the templates from the view to the client side? The main problem is that if you want to extend the template language > with custom tags/filters, you have to write these extensions twice. We > tend to accommodate this by just writing many fewer template language > extensions, doing more display-preparation work in serializers instead, > and relying on Jinja's built-in expressive power (e.g. macros) instead > of template language extensions. > Yeah, I figured as much. I think that Django is in a better position here than other frameworks since actual python code in templates are discouraged. -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/cbcaced0-1def-49be-9816-5895442885fd%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
