Modify Django settings variables in a middleware
-
21-09-2019 - |
문제
I set a variable MAX_REQUEST = 100 in settings.py
I write a middleware which may lower this value for request origining from a proxy ip address by the following code:
settings.MAX_REQUEST = 10
However, looks like the above modification affects all legitimate users.
Is it normal?
해결책
Yes. settings
is a module referenced all over by Django (and probably your code too). Modifying any variable in settings
is like modifying a global variable and alters the behaviour of your whole web app.
다른 팁
Django settings are global. They affect the whole process.
If you want 'per user' variables, I suggest you look at How to use sessions.
제휴하지 않습니다 StackOverflow