--
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 django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
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/5569EAC9.4040503%40kth.se.
For more options, visit https://groups.google.com/d/optout.
IMHO, this can be easily solved with nunjucks.js and jinja which are both interchangeable, but in my experience it's better to had 2 template languages. Using only one tpl gives you the need to implement the same in the django views than in the js controller wich is "harsh" coupled and a PITA.
Also the need to reimplement django.shortcuts.render is unneded. Add in the base tpl a {% if request.is_ajax %} then wrap the result in a entire html tpl for regular http calls and the new content only in the other case.
Another option is to use django_braces and AjaxResponseView to respond back ajax with only json data but again you'll be force to sync django views and the controller for js.
Just my two cents, I'm used to build JS intense sites backed with django without any problem.For me the work should be documenting how to use django with a client MV# and list the options and the apis for that.
I think that Enrique means that having "the same" template language is
a non-goal. the "cognitive burden" of two languages is not so heavy;
and since these two environments are so different, there would be
different considerations that make some features unpractical on one
side or the other; or maybe some choice could be "the best" on one and
too awkward or badly supported on the other.
personally, i mostly agree: i do use templating on JS, and it doesn't
look at all like Django templates. That means sometimes i render some
things in the server, other things in the front end, and a few things
(very few) on both, leading to mostly duplicate code. would it be
nice to have some code that works equally well on either side? yes,
but it's a relatively small gain.
if "using the same language" was so important, we would all be using node.js...
At this point it’s probably easiest for Django to provide templates only for Javascript front-end, and for Django to only serve API endpoints.
We really don’t need Django to serve HTML pages anymore, except for the initial page-load.
--
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 django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
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/783577b2-79f4-4445-81de-3208a16037a4%40googlegroups.com.
implement a template engine that hands over data to a Node.js process, lets it render the template, gets the HTML back, and returns it.
Based on my own experiences building isomorphic JavaScript apps with Django, I haven't had any issues where I felt Django was getting in my way. I've tackled the problem in two different ways, both of which worked without any great difficulty:
1. The primary web-app is actually a node process. Everything you'd consider a view is handled by React and React-Router, data requirements are handled by making an HTTP request to Django REST Framework. This isn't especially efficient, since the base response times aren't great when you're depending on HTTP for data (this can obviously be improved by getting the data via other channels).
2. Use node purely as a rendering engine. I actually created an alternative to TemplateResponseMixin that communicated with a node process via zerorpc (chosen for the sake of simplicity) rather than rendering a template from disk. This abstraction could be made neater by packaging it up as a custom template engine that takes care of converting the data into a format that zerorpc accepts (ie no querysets or rich objects). This approach was significantly faster with base response times of about 8ms for a simple page with no data dependencies, but I felt I was implementing my routing logic twice (once in Django, once in node).
The second approach is easier to get running at acceptable performance levels quickly, but is quite clunky to implement. Going forward I'm probably going to favour the first approach, which essentially means turning my Django projects into nothing more than a data layer, which is fine for me because I've found that once you're using React (or similar) heavily, you're not using much else from Django anyway.
2015-05-30 17:52 GMT+01:00 Emil Stenström <e...@kth.se>:I'm not sure I understand why changes to render() are necessary.If you intend to use the system you've described in your own views, you can use your own variant of render that returns an appropriate HttpResponse subclass.
It's unclear to me that you can reasonably plug such a system on views provided by third-party apps, since context data generated by these views will often not be JSON-serializable.
Could you clarify the reasons for this feature request?To achieve this goal, I think Andrew Ingram's second suggestion is the easiest solution since Django 1.8: implement a template engine that hands over data to a Node.js process, lets it render the template, gets the HTML back, and returns it.That's a good candidate for a pluggable application. It will probably have some specific deployment instructions ("run this Node.js next to your Django...)
--
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 django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
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/da6ffda5-b6b0-4d41-91f0-d6101a3ddd2d%40googlegroups.com.
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.
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.)
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.
On 06/02/2015 11:53 AM, Emil Stenström wrote:
> 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?
I don't have code I can share at the moment, but I'm hoping to blog
about this technique, and I'll let you know if/when I do.
--
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 django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
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/a34fff52-24df-4a54-a512-0553b0ffc322%40googlegroups.com.
That's a problem that I hadn't thought about. I was hoping that querysets where always serializable, but I didn't think of datetime and decimal (and others), which people might send to their views. Are there other pitfalls here? Maybe this could just be else that people would have to change to use the new template backend.