Django Frontend - Templates with React?

Typically you would go for DRF (Django Rest Framework) to start using React or Vue as your frontend framework. But I was wondering is there a good way to use it together with Django templates?

There is currently also an interesting discussion on this on Reddit:

Love to year the input of the Django community here.

I’m not sure there’s a real fit between the Django templates and Vue components. Seems to me that you would end up with a really confusing situation trying to figure out what is being produced where. There’s a real difference between where the data is managed for display in Vue vs Django.

I rely upon the fundamental principle of “Don’t fight the framework” - and I hold that to be true regardless of whether it’s .NET, Spring, Django, or Vue. Try to make your application architecture fit within the design of the framework - don’t try to bend the framework to match your current mental model for your architecture.

However, you don’t need to go the full DRF route. If your needs are limited and well-constrained, you might be ok just creating a couple of custom views that emit a JsonResponse. (We’ve got an application that works that way.)

What I’m looking at for one particular purpose is using Django to dynamically create a Vue dialog box - but again, that’s going to be sent as JSON and not as an HTML response. (You could generate HTML fragments to be supplied to Vue, but my gut reaction to that is that it would be a net-negative.)

I did click through to your link, and I’ll disagree with a couple of his points - going with a front end framework such as Vue does not lose the ability to allow Django to manage security. (As a general principle, you always want your back end to manage security, because you cannot trust the browser.) Also, I disagree that you can only use Vue as an SPA framework. It all depends upon what you’re trying to do. If you’ve got a site with 10 pages and only 1 needs the type of interactivity that Vue provides, then there’s nothing wrong with using Vue on that one page and ignoring it on the rest.

If you go with a hybrid solution, be prepared to provide all your “infrastructure” around your application. You’ll quickly find that some of the “standard tooling” built for frameworks like Vue won’t work if their assumptions (e.g. SPA) don’t hold true.


Thank you for the response it is pretty much what I’m thinking as well and the responses that I got on Twitter

For clarity the link to the Reddit post is not mine I just found it an interesting topic and liked some input from other Django developers. Like you I do not think that you have to choose you could have a mix and you can choose other front-end frameworks like React (which I myself also use as a solution). Security is so easy to use with Django and especially with the dynamic templates and I am glad to read that you think it is appropriate to use Django to manage the security.

I particular like your response in “Don’t fight the framework”.

Thanks for your insights.