Long story short, let's assume I want to create a webpage that would enable the users to sell used cars.
I am a beginner to webdev, so pardon my ignorance. Fun fact: two months ago I knew literally nothing, I considered HTML as a relic of 90s, not in use anymore LOL.
- I've been told I need something for the BACKEND and for the FRONTEND
- As I know python pretty well I went for django for the backend
- As I knew literally nothing about the frontend, my friend suggested me AngularJS
I have some doubts whether I'm heading the right direction.
Django is a backend framework, but my feeling during the tutorials was that the Templates part from the MVT pattern was pretty much the frontend, strongly dependend on the Models and Views. I've spent hours of googling for various terms and found this post on reddit/django - django best practises:
Treat the front end like a separate application. Keep it outside the Django project directory.
So with this approach (just to make sure I understand you), you are not using templates at all, correct?"
You are correct. Not using the templates at all.
How do I do that? I mean, the templates use all those template-tags, how do I replace django templates with Angular code? I feel like I should use some REST API (how? django REST framework?) to communicate the Frontend with Backend. Write only the Models and the Views and connect to them using some POST and GET requests. Like
FrontEnd <---> REST API <---> Django Models and Views <---> Database
Then frontend uses its own logic and sends requests like
- GET give me all the cars a user has posted
- GET user's details
- POST create a new user
- POST a change to a car
- GET query for all red cars
etc.
Then, another question about the frontend. I fell the Angular is not a good choice. It's purpose is to write Single Page Apps, which my clearly won't be. I can imagine a user, querying for some given cars criteria and then opening all of the offers in separate tabs. Is it possible to use Angular for my usecase? I'm lost here :(
If I decide to stick to the django Teplates, how do I use AJAX in there? And is there a way to make a hybrid of Single Page Apps and Multi Page Apps - to generally follow multiple templates, but keep parts of them SPA-like? E.g. A main template used for querying for cars to browse, which would not trigger page reload, instead it would send an asynchronous request, display the spinner and then render the list of available cars. After clicking on a particular car, a new tab would be opened with details on that car (Details template).
I would highly appreciate any help on this frontend/backend separation.