Django: method call only once when django starts

I want to initialize some variables (from the database) when starting Django.

I can get data from the database, but the problem is how should I call the initialize method. And it needs to be called only once.

I tried to search for other pages, but could not find an answer to it.

Currently, the code looks something like this:


def get_latest_dbx (request, ....):

#get data from the database


def get_latest_x (request):

get_latest_dbx (request, x, ...)


def startup (request):

get_latest_x (request)

+5
source share
2 answers

( , Django ?) urls.py ( , urls.py url). , : Django? , ticket.

UPDATE:

OP , , , request . process_request, request. , ( MiddlewareNotUsed __init__, request).

BTW, OP . , Django, , request . Django , . , . , .

+3

. , , , , .

- print 'haha' settings.py:)?

. , settings.py

+1

All Articles