Hacker News new | ask | show | jobs
Ask HN: Is it a good idea to build a Single Page App with Django?
8 points by cneumann81 3771 days ago
I'm wondering, if it is a good idea to build a single page app (e.g., with ReactJS or Angular 2.0) with Django as backend. What's experience? What stack would you recommend, assuming we are staying in Python backend-wise?. Thanks!
10 comments

If you stick to Django, you probably want to look at http://www.django-rest-framework.org/ for the backend.
Am developing two mid-size apps using DRF and Angular. DRF has proved to be quite easy to work with.
I personally find DRF to be my as nice to work with as Django itself. If I can get away with not using it, I avoid it.
Yeah, you will need only a small REST interface for the single page app ...
Would you rather use anything else? Flask for instance?
I feel like that is a matter of personal taste and what your data sources are behind it. Flask makes it easier to do whatever you want, but you also have to do many things by hand, where Django has an included "right" way of doing them.

This recent HN discussion had many opinions and details to read through: https://news.ycombinator.com/item?id=11121355

I've spent a lot of time working with Django as a backend and AngularJS powering the client. It's definitely not a bad combination.

That said, in my personal projects, I lean towards letting Django handle almost all of the client experience too. There are exceptions for areas that are inherently interactive (e.g. WSYIWYG editor), but the vast majority of my projects involve static content. To me, the complexity and overhead of using a JS library/framework outweighs any benefits the library/framework might offer.

I have worked with DRF in the past. It is a very nice framework. However, I came to believe that it is too low-level for new projects. Do you really want to handle at least the following pieces of boilerplate for every API or endpoint?

- Request parsing

- Content negotiation

- Creating/rendering responses

- Subclassing or decorating custom views and/or viewsets

- Model mixins, CRUD glue

- Routing

- Content-type parsing and rendering

- Serialization/deserialization

- Validation

- Authentication

- Filtering

- Pagination

Personally, I found it was harder to get from zero to anything when having to slog through that level of verbosity. I'd rather save brain cycles for harder problems.

It was this experience on the job that led to the design of a better approach with Ramses: http://ramses.tech. You can also generate docs, tests and client libraries this way. If you like the look of that, I will make you an end-to-end prototype for free to help drive home the concept.

Some other awesome projects along the same lines are http://postgrest.com/ and https://flask-restless.readthedocs.org/en/stable/

I've been having success using Django / React together with this: http://owaislone.org/blog/webpack-plus-reactjs-and-django/
You might take a look at Lightweight Django: http://shop.oreilly.com/product/0636920032502.do
Depending on how complicated your API is, you may not need something as heavy as Django. This is a neat little framework if your backend doesn't need to heavyweight:

http://falconframework.org/

It's pretty unopinionated so you have a lot of control and there are less surprises but a lot of the nice to haves are gone as well.

Whatever you go with I would read this as well as the DRF doesn't generate proper RESTful responses on it's own.

http://jsonapi.org/

Related question. Is Django still a good choice for web apps? I mean should I choose one of the newer ones or is Django good enough?
It seems popular still. Do you want a batteries included python web framework? Can't do much better.

In your case, a SPA is not using a lot of Django stuff. So do you really like the admin pages and the ORM? If so use it. If you don't need admin pages and you hate the Django ORM, maybe look at just using Flask?

-- Only used Django a few times so not an expert, but above is my gut feel.

Is your app data-driven? If yes, have you considered Ember.js? At my startup, we're using Ember + Ember Data backed by an API built with Django + Django Rest Framework, and we couldn't be happier with the conciseness and elegance of our code.
Literally a single page? Static content? No, Django is not what you want.

You want to hand-build and hand-tune that page.

Yes. I have done this with Django and Angular 1.x. Works really well.