Answer the question
In order to leave comments, you need to log in
How does AJAX work with django?
Good afternoon, I want to describe in detail how I see the implementation of my project and I want to hear the opinion of programmers who understand this.
I have my own project on Django
. At first I worked according to the old methods, that when a button is pressed, a redirect occurs to the same page,
now I learned a little to work with AJAX, so that when a button is pressed, there is no redirect and the button changes.
My question is, would such a layout be a crutch code, where on the server side, there will be information that the movie is in favorites, and AJAX itself will send only flags that tell the server to add / remove the movie from favorites.
Answer the question
In order to leave comments, you need to log in
where on the server side, there will be information about whether the movie is in favorites,
This is not a crutch, but rather a common solution. Create a new model Favorites, there are two links 1k, add a user and a movie to many, for anonymous users you can also connect the session model, but it’s better to stuff sessions into memcash. Make an additional view that takes an add and del argument and, based on the request, delete or create an entry in the model.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question