Monday, February 21, 2011

Modify Django settings variables in a middleware

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?

From stackoverflow
  • 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.

0 comments:

Post a Comment