I have settings file defined as follows (config/settings.py):
HOST='localhost'
PORT='9001'
When I import settings in view and print the value of each one as follows, it prints correctly (views/user.py):
from ..config import settings
print settings.HOST
print settings.PORT
But when I use or print the same values from inside def it gives error (views/user.py):
from ..config import settings
print settings.HOST
print settings.PORT
@handle_error
def usersettings():
print settings.HOST
print settings.PORT
The function def when called in the above file gives error as follows:
ERROR:root:'function' object has no attribute 'HOST'
Traceback (most recent call last):
File "/home/rahul/mywebapp/webapp/views/utils.py", line 36, in decorated_view
return_value = func(*args, **kwargs)
File "/home/rahul/mywebapp/webapp/views/utils.py", line 27, in decorated_view
return func(*args, **kwargs)
File "/home/rahul/mywebapp/webapp/views/user.py", line 344, in usersettings
print settings.HOST
AttributeError: 'function' object has no attribute 'HOST'
utils.py has decorated view named handle_error
My Package structure is as follows:
mywebapp/
run.py
webapp/
__init__.py
views/
__init__.py
utils.py
user.py
config/
__init__.py
settings.py
FYI: This use to work till last night and suddenly it has started behaving weird with the above error. Whats is a wrong that I am doing here?
EDIT:
My init.py are as follows:
from .utils import *
from .user import *
settingsfunction to that module. The function is not yet there when the module is imported (at least not where you printsettings.HOST), but by the timeusersettings()is called,settingshas been rebound to a function object.settingsfunction in your code, which explains this behaviour.user.py?settingsand check that there are nodef settings(...)lines orsettings = something else.