0

Suppose I have some data in my view function that I want to use the next time I am in that function. The data is specific to each person that uses the website, so cannot be static or global, and it will change as the person uses the website. There are two methods I can think of to load this data into memory when the view function ends:

  1. Send it as part of the context each time a template is loaded from the view function, and then send it back to the view function via request.POST.
  2. Store it in the database and load it each time the view function is called.

The first one seems like it would be faster, but can be cumbersome if the data is complex.

Is there a third solution? What is the best practice? Is this what Django sessions are all about?

1 Answer 1

1

If it's ephemeral, store it in a session. If not, treat as a user preference, store in a record related to the user.

Sign up to request clarification or add additional context in comments.

1 Comment

It would only last very briefly during the user's immediate period on the website. It is not something that would be loaded again when the user logs in a few days later. So I guess that it should be stored in a session. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.