imran_44
imran_44

Reputation: 329

How to implement Angular with Django

I have requirement for creating an application using Angular(TypeScript) as frontend and Django as Backend, where I will be working only on Django (backend). Is that creating an REST API only enough to communicate with front end. Is that only possible in the backend in this case?

Normally while working in Django I used to work in forms, views and will renders in the html and create API for it but in this case where I have no idea how angular would work even. Just creating an API only sufficient when communicating with Angular

Upvotes: 6

Views: 13102

Answers (2)

GlenH
GlenH

Reputation: 151

Yes, creating API's using Django/DRF is sufficient to communicate with an Angular app.

Below is an illustration of a basic architecture of a Django Angular application.

Architecture of Django/Angular app

API endpoints in Django will be served via the urls.py files using the DRF (Django Rest Framework. The angular client will send HTTP requests using the Http Client Module and display the retrieved data on the components/pages. A data service created in Angular will use the HTTP client to send and get data. Angular Router will handle navigations to pages and components.

Upvotes: 13

farincz
farincz

Reputation: 5173

Yes, you will be using Django for REST API views. Forget about templates and Django forms, you will be just sending and receiving JSONs.

If you want to host it together you will be probably serving just index.htm. The tricky part is that you need match all possible app routes to index too (the whole Angular lives there, handling routing on client side. But initial request after reload still can lead to arbitrary url)

More common way is using two separate containers, one for api and one for angular app. Then you can provide server side rendering on angular app (this will be still calling api from it) and separate api without need to handle index.

Upvotes: 5

Related Questions