Chandler.Huang
Chandler.Huang

Reputation: 893

How to preload django's view at application start?

I wrote some global variable which takes some time to initial in views.py. Instead of responding after requesting, I would like to make those variable initialed while the server starting. Is there any way to do it? I have try google about it but in vain. I think I couldn't be the first one have this kinda of needs. Thanks.

Upvotes: 1

Views: 500

Answers (1)

dani herrera
dani herrera

Reputation: 51675

It seems you are talking about settigs, that means, variables that are fixed at start time.

You can set this kind of vars in settigs.py and access them importing settings:

settings.py

MYSETTING = some expression

views.py

from django.conf import settings
...
mycalc = ... MYSETTINGS ...

Upvotes: 1

Related Questions