Bill TheKid
Bill TheKid

Reputation: 63

What is the correct way to change html dynamically using django

Suppose we have a login page where, in the first stage, we are asked to enter our email. We send this information to the server, which searches whether there is an account with this email, and if there is, our goal is to change the state of the page, to a page where the user is asked to enter the password for this account. If, on the other hand, there is no account with that email, the state of the page changes to one where the user signs up. And let's say that, for the sake of aesthetics, all this happens using the same url.

My question is, what is the correct way to inform the client's page to what stage to go into?

Sending the whole html code is an option, but this seems like it will put too much pressure on the server. Is there a cleaner way, that we can send less information, and still be able to have the same result?

I am new to django and web dev so please explain thoroughly.

Upvotes: 0

Views: 183

Answers (1)

sherdim
sherdim

Reputation: 1236

For a browser engine submitting a form with email is a new page request and a new rendering of HTML after that. The source of new HTML code is your server with Django, so you should generate a new HTML with a relevant template and send it as a response.

Such user provoked events change a state of your application for a given user session, not a page.

For speed you can use caches for styles, for menus, for HTML snippets (headers and footers). Also you can make a one-page application, but you must use JavaScript framework for it. Then your JavaScript code executing in client's browser can request concise JSON with necessary information instead of full HTML. Then your JavaScript framework is responsible for a correct insert new dynamic HTML elements in the current document object model (DOM).

Upvotes: 1

Related Questions