Django REST with SPA - what structure - django

Django REST with SPA "within" or completely stand alone?
I'm diving into a new project where I'll try to build a SaaS web application and I've set on using Django Rest (with Postgres to utilize schemas) and React/Vue on the frontend.
What I'm unsure and what I can't seem to get an answer to is the way people structure these frameworks. E.g, on https://www.valentinog.com/blog/drf/ the author writes:
I see the following patterns (which are common to almost every web
framework):
React in its own “frontend” Django app: load a single HTML template
and let React manage the frontend (difficulty: medium)
Django REST as a standalone API + React as a standalone SPA
(difficulty: hard, it involves JWT for authentication)
Mix and match: mini React apps inside Django templates (difficulty:
simple)
And here are my advices.
If you’re just starting out with Django REST and React avoid the
option 2.
Go for option number 1 (React in its own “frontend” Django app) if:
you’re building an app-like website
the interface has lot of user interactions/AJAX
you’re fine with Session based authentication
there are no SEO concerns
you’re fine with React Router
Why is this beneficial, and is it actually different from having a stand alone rest api and a standalone SPA? The reason I wanna use Django is so I don't have to worry about authentication and authorization, and I also plan on utilising the admin panel - will this "not work" if I were to use two completely standalone applications for the backend and frontend? (e.g django rest with the sole purpose of exposing the api and the frontend to consume it).
What alleged benefits do I get from having django rest and SPA in the same "root" project

Related

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
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.
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.
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.

Django + Angular

i am new to the world of web development and i have a very good foundation on django for backend operations. i am also learning angular for front-end applications. so far i am quite happy writing in django for backend, but i dont like to work with the django templates. My question is, is there any way to integrate angular as the front-end portion in a django environment, keeping the django as the backend??
also while we at it, is there any good designing (UI design) courses available and where (free or paid)?
What you were doing was using Django as a backend and frontend framework. But you can use Rest Framework to build an API, keeping Django only on the backend. Once you have the API endpoints built, you can consume them with Angular or any other framework.
More info:
What is an API?
The tutorial in the official website of Django Rest Framework is a great start.

How site administration is managed in Django-Angular2 project

I have to use Angular 2+ for front-end and Django as back-end, in my project.
Usually Django provides the '/admin' URL through which we can access the admin portal to do all the site-administration stuffs. But to use Angular 2+ as front-end we need to convert the whole back-end (Django) into REST API, which is actually recommended.
In this case how can we use the Django Admin URL or its utilities from Angular URLs? Or else whether I have to replicate Django Admin in Angular 2.
It will be a great help if someone can give me some ideas on this.
You seem to have a misunderstanding of how the various technologies you are developing in actually coexist.
Django is the server-side framework.
DRF (Django REST Framework) is
used in addition to Django, to make it easier to implement a
RESTful API on top of your Django project. Django REST Framework does
not replace Django. Django REST Framework is an addition to
Django.
AngularJS is a JavaScript framework that can be used in your project (or just parts of your project).
Using Django REST Framework does not suddenly mean that the Django admin interface will 'stop working'.
If your project's URL routing ('urls.py') still contains a route connecting the Django admin interface with /admin you can still go to yourproject.com/admin and it will completely circumvent anything you've done with AngularJS.
It may be late to reply, but Angular and DRF connects over http call.

Can Django be used to combine both webapp and moblie api?

I want to use django framework to write a web site with static/dynamic pages (I will not be using angular/react - i.e. SPA technology) but I also want the web app to serve as the backend for a mobile app.
What's the best practice here? Can Django alone be used for it?
Will I need to use Django REST framework?
If you could recommend some specific modules to keep the app as simple as possible and avoid DRY code. That'd be great.
Thanks.
You have the right pointers in your question already.
Use django-rest-framework to create a rest service, create your web app in django to consume that service, create a mobile app to consume the same rest service.
In general, once you have a rest service, you can build anything on top of it. Just consume the service from whichever platform you want to build for.
I hope that helps.

What is the role of django REST framework if I want to integrate angularjs with django?

I am trying to set up django with angularjs and play around with it. Most of the tutorials contain something about django REST framework, Creating endpoints for an application, APIs and so forth. What is django REST framework, what are endpoints, APIs, why are they important for angular?
First of all, you should learn what is angularJS and how it works, with that knowledge is pretty clear why there is need for an API.
In short words: You feed angularJS with template and data, AngularJS will take it and build correct site on client side. There won't be any benefits if you won't change data dynamically. That's why you need to have API for you app (to exchange data, not pre-build templates) and for that API, good choice is Django Rest Framework.