Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

I also think django templates is not up to par in 2017, and use typically Django as an REST API platform; A node/react server would call the API and render the html.


sort by: page size:

If a project requires server-side rendering, I render it using React on a Node server. I don't use Django templates for anything these days.

Curious what you mean, more specifically? Django template language seems fine to me, but maybe I haven't used React enough to see where it is better.

I think that what they mean is not to use Django's templates, but to use it as an API server. Django's DRF is one of the easiest ways to create and maintain resource endpoints.

Nginx would serve the index.html with the scripts and the React components would request their data to the API.

This of course doesn't consider SSR'd React as it is just to get started, but the community is working on it (see pipy's projects)


Django templates are the worst.

Django is great. Just don't use its templates or form systems. Indeed react is a great replacement for both.


I didn't single Django out, I think all server-side template languages are hideos and largely unnecessary. JavaScript templates, with some work, can be better in a lot of ways.

Not a Django person, but I've used a few server-side templating languages, and I agree. I'd love to go mostly/entirely server-side, cut down on boilerplate AJAX calls, and ship smaller/less JS-heavy sites to the browser. But I'd also like to write my view logic in a full language, with typechecking and a solid developer experience. I'm hopeful React Server Components will help with at least some of this.

I totally understand people's preference to use Django templates wherever possible, and only sprinkle in more frontend focused stuff when needed, but personally, I would rather just write the whole frontend in React or Vue.

This is probably partly due to the fact I find working with django rest framework serializers / views to be much nicer than django forms / views.

I think what puts most people off is the default requirement to go all-in and create an SPA with global state management and client-side managed routing, but this isn't actually necessary.

I have found incorporating Django with https://inertiajs.com to be a pretty solid alternative. I can write the whole frontend in React, and the backend in Django rest framework, but everything is still page based, so I don't require redux or any other kind of global state, just use the inertia utils to make page transitions.

NextJS is another alternative. To talk to a (django) API you need to go through getStaticProps and getServerSideProps which, depending on the location of your API server, can be a little slow, but you get pre-rendered HTML and page based routing so again no global state management required.


Thanks! Are you using the Django template language on the server or using React somehow?

react templating language is better than Django templates

> For example I’d choose React + Typescript over Django templates any time of the day.

What's stopping you? I use Django Rest Framework to write views and React + Typescript for the front end. Using templates is often way simpler, though.


I'm working on a Django app where most of the frontend is old school Django templates with some JS on top. Kinda comfy.

Shameless plug: If you want seamless SSR with Django logic, but React templates, check out my project at https://www.reactivated.io .

It's like HTMX but uses React, and the JS bits are rendered on the server. You can then hydrate on the client.

The Reactivated docs site itself uses the project: https://github.com/silviogutierrez/reactivated/tree/main/web...


I have to agree, Django templating (last I saw) was stuck somewhere in Web 1.0

Jinja2 is better, but most of the time, I would just build the API and not bother with rendering anything on Django itself


As the sibling comment says, while I disagree with specifics this article is full of gems.

@Alex3917 What do you think of using Django-rendered templates for views that don't require significant frontend interactivity?

You seem to advocate the "everything is an SPA + Rest API" approach, which I thought was interesting.


Like others have mentioned, I love django for all the batteries-included features (admin, sessions, ORM, etc). But I still haven't really found a good way to use Django with React JSX as the template engine -- rendering & caching serverside for SEO purposes, but still responsive client-side.

I haven't seen a good description of how to pull this off... but it would make a great eBook (I'd buy it!).

It seems like the Django RESTful API would be one solution... but it would result in a lot of extra REST requests (so blocking & latency) being generated during server-side rendering, so perhaps not the best solution.

Thoughts?

(I am aware of solutions like this, but it misses the server-side rendering aspect with contexts: http://stackoverflow.com/a/28646223 )


I am also not in a Django shop.

But I don't think Django templates are safe in a way that they protect the backend from a clueless or malicious frontend developer. Even if they were, you would have to take great care that you do not expose dangerous functionality. So "give them access to the Django template itself" is not enough. You would have to have a whole security concept around it.

And that is not enough. How does the fronted dev create routes? How do they create views, which are the glue between the DB and the templates?

Node.js is a runtime, not a framework. It does not have routes, views or templates at all. So that comparison makes no sense.

No matter which backend framework you choose - you will have a lot more work to bring the frontend dev into the game if you do backend rendering.

Please be aware that I am not against backend rendering. I indeed think that backend rendering is the better approach! I just explain here why there is some appeal to developers to write the backend as an API and do the rendering on the frontend.


You are not required to use Django's templating engine. It works great with React, Vue, Angular, etc. if you use Django Rest Framework as the intermediary.

Well, It is more of a design problem than a Django template problem. If you add more and more logic in the template itself instead of dealing with it in the views context or templatetags, you are bound to find yourself in such position that you have very hard to test code.

The tooling is fine and almost always lets you know where you are breaking stuff. Also, comparing react tooling with it is not fair, it is a much modern ecosystem that has pitfalls of its own.

I have been writing Django professionally for 10 years and React + Django together for 4+ years, so I really know what I am talking about here.


I've found this problematic in Django: How to integrate a good JS frontend that isn't at odds with the built-in templating system. Offloading the templating to React (eg. node / JSX) seems like a good bet -- but then your Django app is little more than a REST API.

I'd love to see some good, practical examples of a full-featured (ie. integrated) Django app with a js frontend. Pointers welcome!

next

Legal | privacy