Answer the question
In order to leave comments, you need to log in
AJAX with DJANGO, what is possible and what is not?
Just starting to understand ajax + django. In the template, I have the following logic: if the user is not authorized (if user.is_anonymous), a registration form is displayed, (if user. is_authenticated) a welcome message and an exit button are displayed. Accordingly, I want to make authentication without reloading the page. The next question is, as far as I understand, in order to check the conditions, you need to reload the template? Therefore, the only way is to return data to the ajax request, for example, the user's login in case of successful authorization, and then in js - to replace the login form with a greeting. Or you can still achieve a "rebuild" of the entire page, without reloading the page). All that I found on the Internet and documentation - return to ajax httpresponse or jsonresponse
Answer the question
In order to leave comments, you need to log in
Therefore, the only way is to return data to the ajax request, for example, the user's login in case of successful authorization, and then in js - to replace the login form with a greeting.
How do you imagine rebuilding the already loaded html from the server side? Here, either an ajax request and editing the block using js, or reloading the page after receiving a response to the request.
You do not need to return the data, the "success/error" status is enough, because you already have the user's login, you send it for verification.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question