[Answer]-Persistent dicts across user sessions

1đź‘Ť

âś…

Fundamentally, this is what the database or some other external data store is for. You need to configure a database like Postgres or an in-memory data store like redis to store this information for you in a structured way.

The reason for this is that Django applications are not supposed to hold on to any information between sessions, by design. Django applications are meant to be run on multiple processes and multiple servers concurrently, so the applications need to be configured to access external data stores so that work like this can be shared between web app processes.

There is no other correct way to do this — writing a file directly to your disk, for instance, will not work with concurrent access, which is a requirement for any website of any size (especially if you are working on a security-related feature).

The answer to your updated question is, “no”. There is not, for the reasons above. I’m not saying it’s literally impossible, but it’s not the right way to make this kind of software so the framework will not make it easy for you.

0đź‘Ť

Your app will most likely lose that kind of data on restarts, or even between two requests (depends what kind of server you’re running it on of course).

But since you need the data to be persistent, why not just stick it into the database? Or if you prefer to have it handled very quickly, in some kind of in-memory store. Memcache, or redis should do quite well for this use case. Redis can even give you things like storing sets, which would help for the BLOCKED_IPS lookup.

👤viraptor

Leave a comment