In my local environment the django development server works fine with no errors.
When I run the app on a production environment with nginx & gunicorn I get this error:
AttributeError: 'NoneType' object has no attribute 'find'
This is the source of the error:
if cache.get('ratings').find(name_input) == -1:
result = food.objects.get(name = name_input)
I have memcache imported:
from django.core.cache import cache
and in my settings.py:
CACHES = {
'default': {
'BACKEND':
'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
I expect the webpage to work without errors
——–EDIT:————–
Providing more info I have a JSON script in my HTML section that sends the variable to python.
Then python catches it.
I repeat that everything works like charm locally.
===================================
——–Edit new——
I have tried to change the location of memcache to point to my server in “settings.py”:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': 'MY_IP:11211',
}
}
but this attempt didn’t work
I can print normally to the syslog, the values ARE NOT NULL
2
Answers
The error was that I didn't have memcached installed in the first place; even though I used this command to install it:
Then I used another command instead:
and everything works fine now :)
I believe that the
cache.get('ratings')
is unable to find the string ‘ratings’ so it returns NoneType by default, so it’s unable to use the .find attribute.You should try printing the cache to see if there is the string ratings inside it