Re: Choosing a JS framework to go together with Django

1,932 views
Skip to first unread message

Alec Taylor

unread,
Sep 4, 2012, 10:23:49 AM9/4/12
to django...@googlegroups.com
AngularJS?

On Tue, Sep 4, 2012 at 11:39 PM, dotnetCarpenter <jon.ron...@gmail.com> wrote:
Hi all.

I'm new here and just took over a Django project for the first time. I'm still getting to grip with Django but as a front end dev for the past 5 years, I'm also looking for a client-side library/framework to go together with my project.
My requirements for a JS framework is that it:
  1. is unobtrusive (Django rendered HTML will be shown to scraper bots like google)
  2. provides some sort of structure (MVC, MVP, MVVM ect.)
  3. embraces standards
  4. doesn't conflict with Django templates or does so intentionally
  5. ideally uses the same template language as Django

In the ideal world a request/response scenario would look like this:

  1. A client make a (HTTP) request to the (django powered) web site with (HTTP) Accept header text/html
  2. Django response in the usual way by rendering the assign View (django template)
  3. The view figure out if JS is supported (implemented in JS). If no, this scenario stays in loop 1-3. If yes, then 4.
  4. The client (usually a browser) wire up the client-side app structure, hook in to URI links, add transitions between views, data-bindings ect.
  5. Subsequent request are now handle by the JS framework, either user initiated (e.g. clicking a link) or app initiated (e.g. pulling extra data), that will modify the request header to Accept header application/json or application/django-template.
  6. If django receive a request with an application/django-template header it will serve the view as plain text. E.g. Content-type: text/plain. On the other hand if django receive a request with application/json, it will send the object model defined in the view as JSON.
  7. The client-side JS framework will receive a template to render in the first request and the data to render in the template in the second request. A promise object could be used to synchronize the two calls.

This way django will work as intended for non JS clients and silently convert to a RIA in clients that supports JS, with minimal double work for the two execution contexts.
A big pro in this is the fact that both django and the JS framework share template and data (only has to defined once - in django) - we'll duck type all the way. But does this JS framework exist? Does anyone have any experience with working with django and JS frameworks? Is there any obvious pitfalls in my ideal world scenario in regard to Django? And finally, is it possible to serve templates as plain text with django?


Cheers, Jon and thanks in advance

PS. I accidentally cross-posted this to the Django Developers group before realizing it was the wrong forum. Sorry about that.

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

Marcin Tustin

unread,
Sep 4, 2012, 10:24:35 AM9/4/12
to django...@googlegroups.com
Why?
--
Marcin Tustin
Tel: +44 (0) 7773 787 105 (UK)
       +1  917 553 3974 (US)


Alex Strickland

unread,
Sep 4, 2012, 10:35:07 AM9/4/12
to django...@googlegroups.com
On 2012/09/04 03:39 PM, dotnetCarpenter wrote:

> I'm new here and just took over a Django project for the first time. I'm
> still getting to grip with Django but as a front end dev for the past 5
> years, I'm also looking for a client-side library/framework to go
> together with my project.

AngularJS from Google seems well thought of and is completely back-end
agnostic as far as I can see.

I'm a n00b on client *and* server development so take it with a pinch of
salt, but I have done quite a lot of reading.
--
Regards
Alex

Peith Vergil

unread,
Sep 4, 2012, 10:38:07 AM9/4/12
to django...@googlegroups.com
i've been playing with KnockoutJS lately. one thing i like about it is that it's built-in templating engine has a different syntax than Django's, so there shouldn't have any conflict.

Rafael E. Ferrero

unread,
Sep 4, 2012, 10:55:07 AM9/4/12
to django...@googlegroups.com
men, i use Jquery on www.expoferiasg.com.ar and works quite well.. with any problem.

2012/9/4 Peith Vergil <peith....@gmail.com>
i've been playing with KnockoutJS lately. one thing i like about it is that it's built-in templating engine has a different syntax than Django's, so there shouldn't have any conflict.

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



--
Rafael E. Ferrero
Claro: (03562) 15514856

Paul Menzel

unread,
Sep 4, 2012, 11:01:50 AM9/4/12
to django...@googlegroups.com
Dear Rafael,


Am Dienstag, den 04.09.2012, 11:55 -0300 schrieb Rafael E. Ferrero:
> men, i use Jquery on www.expoferiasg.com.ar and works quite well..
> with any problem.

s,with,without,?

Additionally your site does not tell my browser what character set it is
using and therefore all special signs are not displayed correctly in a
browser using UTF-8 by default.

And last but not least, though not so important on this list, plain text
messages are preferred on mailing lists [1]. ;-)


Thanks,

Paul


[1] http://en.opensuse.org/openSUSE:Mailing_list_netiquette
signature.asc

Rafael E. Ferrero

unread,
Sep 4, 2012, 11:08:31 AM9/4/12
to django...@googlegroups.com
Sorry paul... my bad... "without any problem" i mean.

extract of index.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
...
do you see something wrong there, maybe a mistake??

2012/9/4 Paul Menzel <pm.d...@googlemail.com>

Paul Menzel

unread,
Sep 4, 2012, 11:48:40 AM9/4/12
to django...@googlegroups.com
Am Dienstag, den 04.09.2012, 12:08 -0300 schrieb Rafael E. Ferrero:
> Sorry paul... my bad... "without any problem" i mean.
>
> extract of index.html:
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
> ...
> do you see something wrong there, maybe a mistake??

Strange. Loading it now worked without problems. Sorry for the noise,
although I think you should add two more »"« after html and before
utf-8.


Thanks,

Paul
signature.asc

Melvyn Sopacua

unread,
Sep 4, 2012, 12:14:59 PM9/4/12
to django...@googlegroups.com


Op 4 sep. 2012 16:38 schreef "Peith Vergil" <peith....@gmail.com> het volgende:


>
> i've been playing with KnockoutJS lately.

+1 on knockout.

Tom Evans

unread,
Sep 4, 2012, 12:37:37 PM9/4/12
to django...@googlegroups.com

Paul Menzel

unread,
Sep 4, 2012, 4:58:06 PM9/4/12
to django...@googlegroups.com
Right. Thanks, I should have checked before suggesting something.


I will shut up now and keep wondering why Midori did not display it
correctly the first time I viewed the page.


Thanks,

Paul
signature.asc

Kelly Nicholes

unread,
Sep 5, 2012, 10:34:29 AM9/5/12
to django...@googlegroups.com
It would be a travesty to not mention backbone.js.

On Tuesday, September 4, 2012 7:39:49 AM UTC-6, dotnetCarpenter wrote:
Hi all.


I'm new here and just took over a Django project for the first time. I'm still getting to grip with Django but as a front end dev for the past 5 years, I'm also looking for a client-side library/framework to go together with my project.

Amyth Arora

unread,
Sep 5, 2012, 2:13:52 PM9/5/12
to django...@googlegroups.com
I am not sure what you are exactly trying to achieve. A more issue specific topic would have been easy to understand though i can suggest you following frameworks (in particular order):

1. KnockoutJS
2. BackboneJS
3. Cappucino
4. Ember.Js
5. Sammy.JS
6. Spine.JS
7. JavascriptMVC

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/PF4D-xIEovcJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Thanks & Regards
----------------------------

Amyth [Admin - Techstricks]
Email - aroras....@gmail.com, ad...@techstricks.com
Twitter - @a_myth_________
http://techstricks.com/

dotnetCarpenter

unread,
Sep 5, 2012, 11:14:15 PM9/5/12
to django...@googlegroups.com
Wow - a lot of answers. Great community!

First of all, just to clearify. My aim is to have smooth user experience while utilizing Django and replicate as little code as possible on the client and the server. Think, reuse of server code on the client.

I've looked at AngularJS and it has a rendering layer that doesn't work without JS. Hence, no google support since google still requires us to deliver HTML snapshot. Which means it violate my first requirement. AngularJS doesn't seem to offer help in this regard. https://groups.google.com/forum/?fromgroups=#!topic/angular/yClOeqR5DGc

Almost all JS frameworks in the wild, violate simple SEO rules, so it's not confined to AngularJS at all.

jQuery doesn't dictate client-side rendering. but doesn't offer any structure at all. Albeit it's great to build your own structure on top of.

Thanks for the list of frameworks. I haven't look at Knockout yet but it seems to require JS to do it's data bindings.

Cheers, Jon.

dotnetCarpenter

unread,
Sep 5, 2012, 11:18:04 PM9/5/12
to django...@googlegroups.com
Hi vicherot.

I'm interested to know how you made the distinction between your dhtml/ part of your site to the shtml/ part. It looks like you pretty much used the same code base to generate the 2 versions. Can you elaborate on the Django specific parts of your implementation?

Cheers, Jon

dotnetCarpenter

unread,
Sep 5, 2012, 11:21:12 PM9/5/12
to django...@googlegroups.com
@Peith Yes, I can see the advantage of not having to spend time working out template conflicts. But you'll have to write two sets of template code, right? One for Django and one for KnockoutJS. Or am I missing something?

Cheers, Jon

dotnetCarpenter

unread,
Sep 5, 2012, 11:30:30 PM9/5/12
to django...@googlegroups.com
@Kelly Nicholes In backbone.js everything is in JS, meaning that there could be no conflict between declarative code and Django handled templates. If I can expose my python models, through auto serialization (JSON) from Django, I can see a productivity win. But I'm a little afraid of the tight coupling in data models between back-end and front-end. My main concern is that I'll have to rewrite large parts of JS if/when the models change. Have you any experience ironing out these issues? Maybe it's not a problem but I lack experience with both frameworks.

I'll look more into backbone.js :)

martharotter

unread,
Nov 4, 2012, 10:10:10 PM11/4/12
to django...@googlegroups.com
Hi Jon, 

I was just wondering if you made a decision on this? I'm looking at a similar approach and am wondering what direction you ended up taking and why? 

Currently looking at Knockout myself but open to suggestions. 

Thanks!

--Martha

Joni Bekenstein

unread,
Nov 5, 2012, 8:53:06 AM11/5/12
to django...@googlegroups.com
By writing a custom serialization for your models you have a good place to handle variations to those models. You don't really have to dump all of your fields, you can even create a custom field specifically for the frontend, but doesn't really exists in your backend model. 

Besides, If and when your model changes, the frontend part that depends on what changed will probably have to be adjusted, regardless of it beeing a plain old django template or something else.

Faraz Masood Khan

unread,
Nov 5, 2012, 10:32:48 AM11/5/12
to django...@googlegroups.com
Have a look at following Unobtrusive Ajax, it is plug out of ASP.NET MVC, simple yet powerful.

dotnetCarpenter

unread,
Jul 14, 2013, 8:18:51 AM7/14/13
to django...@googlegroups.com
In the end, my project stalled due to lack of resources. We might pick it up but it's been abandoned for quite some time. I haven't had any django projects since. Hence, I can't make any recommendations.

DjangoAjax looks promising but might lack the community support you expect. It is however based on jQuery and ASP.NET MVC, so if you can see past the M$ cruft, some guides etc are available.

Phang Mulianto

unread,
Jul 14, 2013, 9:16:05 AM7/14/13
to django-users
Hi ,

Why not using REST for serving your data to the Front End app, it can be from mobile app or just web app with HTML + javascript.

With that you don't need to worry about redo the template side in django and in your front end js app.
With REST serving JSON, no template / html needed for the response.

You can use Tastypie or Django rest framework which still using Django engine . This way also your application server no need to rendering the HTML view in every request from the first time.

Any front end will be able to process the JSON with javascript.

Regards,

Mulianto


On Sun, Jul 14, 2013 at 8:18 PM, dotnetCarpenter <jon.ron...@gmail.com> wrote:
In the end, my project stalled due to lack of resources. We might pick it up but it's been abandoned for quite some time. I haven't had any django projects since. Hence, I can't make any recommendations.

DjangoAjax looks promising but might lack the community support you expect. It is however based on jQuery and ASP.NET MVC, so if you can see past the M$ cruft, some guides etc are available.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.

Jon

unread,
Jul 14, 2013, 10:52:19 AM7/14/13
to django...@googlegroups.com, django-users
The idea is to generate pure HTML views for non JS clients like search bots. If your view depends on AJAX calls, then it defies the purpose.

I've been developing native mobile apps for the past year, so I get your argument about providing REST end points for your data.

The point of my original post was to NOT do two different views; one for search bots and one for browsers.
 I agree that providing a REST interface is the "right" way to provide data for both browsers and mobile apps. To that end, the project I was suppose to work on, used tastypie.

// Jon
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/X_9qJJjiDfE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

François Schiettecatte

unread,
Jul 14, 2013, 11:02:24 AM7/14/13
to django...@googlegroups.com
Hi

FWIW an approach I have taken is to split the app into two components, one is a REST based API (developed in Java, but you could use Django), and a website developed with Django. The website renders pages of content (all SEO friendly, with known urls), all interactive JS is provided by jquery, and I use the '/ajax/...' url for browser calls to the website app (validation, autocomplete, etc...). This split gives you the option to develop mobile clients against the API, and to host components on different machines. If you want to start small one option would be to build you API with Django and use the '/api/...' url. That way you can combine API and website on the same server until you need to split things. And using host names like api.foo.com and foo.com makes that relatively painless.

François
Reply all
Reply to author
Forward
0 new messages