Sankalp Chawla
Sankalp Chawla

Reputation: 39

What is the best architecture to integrate AngularJS with Django?

I am trying to integrate Angular with Django. I have 2 approaches which one is the best way:

  1. Build a separate angular app and serve it's static files to django to render. In this way the routing and rendering everything will be handled by Angular.

  2. Or to build templates in django using Angular directly and use MVT architecture of Django only.

Which is the correct way from architecture point of view? If not these two please suggest any good approach.

Upvotes: 0

Views: 145

Answers (1)

lbris
lbris

Reputation: 1249

I'm not using AngularJS (actually I'm using VueJS but it's kinda the same) but here is what is usually done :

  1. You do your models as usual, using Django. It defines your database structure.
  2. You build an API that exposes your datas. For that you can use DRF (Django Rest Framework) for a REST API or graphene-django to build a GraphQL API)
  3. You code components to build pages. And you retrieve your datas to display from the API.

For my project, I personnally use :

There are lots of tutorials on how to combine all of these so I guess there are some for AngularJS too.

You should be able to do something similar with AngularJS.

Finally, it is more like the first approach that you described. You'll have some build step that will create a bundle of files with a index.html or similar. The thing to do is to tell Django : "Hey, for any URL, point to that file".

Note that the thing I'm describing is for building a SPA (Single Page Application).

Upvotes: 1

Related Questions