django-imagekit
django-imagekit copied to clipboard
Asking for various 'settings'
I have previously used django-imagekit in fresh projects and it ran more or less out-of-the-box.
Currently, I am trying to integrate it with some legacy code (django-1.4) running inside a virtualenv. When I try to upload an image it gets uploaded but querying the thumbnail (ImageSpecField) gives errors regarding missing settings. (It never occurred in any of my previous projects).
Using the docs @ http://django-imagekit.readthedocs.org/en/devel-0/configuration.html, One by one, I tried to add the settings myself in settings.py:
IMAGEKIT_DEFAULT_CACHEFILE_BACKEND = 'imagekit.cachefiles.backends.Async'
IMAGEKIT_CACHE_PREFIX = 'imagekit:'
IMAGEKIT_CACHEFILE_DIR = '/home/userx/devpt/misc/'
IMAGEKIT_CACHEFILE_NAMER = 'imagekit.cachefiles.namers.hash'
IMAGEKIT_SPEC_CACHEFILE_NAMER='imagekit.cachefiles.namers.source_name_as_path'
But it finally breaks down, when I give this attribute (it gives missing attribute in settings, if I do not specify it):
IMAGEKIT_DEFAULT_FILE_STORAGE = None
'NoneType' object has no attribute 'rindex'
bt = test.banner_thumb.url if b else None ... # My code
/home/userx/devpt/virt/lurnq/local/lib/python2.7/site-packages/imagekit/models/fields/utils.py in __get__
file = ImageCacheFile(spec) ...
/home/userx/devpt/virt/lurnq/local/lib/python2.7/site-packages/imagekit/cachefiles/__init__.py in __init__
'file storage backend') ...
/home/userx/devpt/virt/lurnq/local/lib/python2.7/site-packages/imagekit/utils.py in get_singleton
cls = get_by_qname(class_path, desc) ...
My spec looks like:
banner = models.ImageField(upload_to=banner_name,
blank=True, null=True, max_length=2048)
banner_thumb = ImageSpecField(source='banner',
processors=[ResizeToFill(100, 100)],
format='JPEG',
options={'quality': 80}
)
Hi @drepo! You shouldn't be setting IMAGEKIT_DEFAULT_FILE_STORAGE
to None
: you should either omit it (in which case settings.DEFAULT_FILE_STORAGE
will be used) or set it to a full class path like myapp.stuff.MyFileStorage
.
Do you think you can share the original error? (The one you get without all those settings.)
Hey, i have to say, i've got the same problem. I tried to install Imagekit 3, but it always asks for various settings. If i do enter all that settings above, i get the same error. Imagekit 2 is working. Any ideas? (I don't have any special settings.)
@svschannak Can you share the error?
AttributeError at /verwaltung/produkte/uploads/160/
'Settings' object has no attribute 'IMAGEKIT_DEFAULT_CACHEFILE_BACKEND'
Request Method: POST
Request URL: http://127.0.0.1:8000/verwaltung/produkte/uploads/160/
Django Version: 1.6.1
Python Executable: HOME_DIR/.virtualenvs/prototyp_stb/bin/python
Python Version: 2.7.5
Python Path: ['HOME_DIR/prototyp', '/Applications/PyCharm.app/plugins/sass/lib/stubs/sass_functions.scss', 'HOME_DIR/prototyp', 'HOME_DIR/.virtualenvs/prototyp_stb/lib/python27.zip', 'HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7', 'HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/plat-darwin', 'HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/plat-mac', 'HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/plat-mac/lib-scriptpackages', 'HOME_DIR/.virtualenvs/prototyp_stb/Extras/lib/python', 'HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/lib-tk', 'HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/lib-old', 'HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', 'HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages', 'HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/newrelic-2.6.0.5']
Server time: Mon, 16 Dec 2013 02:21:34 -0600
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'prototyp',
'imagekit',
'south',
'tastypie',
'tastypie_swagger',
'gunicorn',
'django_facebook',
'djcelery',
'verwaltung',
'bootstrap_toolkit',
'bootstrap3',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "HOME_DIR/prototyp/verwaltung/views.py" in upload_product_files
25. image_file = ProductImage.objects.create(picture=file)
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/django/db/models/manager.py" in create
157. return self.get_queryset().create(**kwargs)
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/django/db/models/query.py" in create
319. obj.save(force_insert=True, using=self.db)
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/django/db/models/base.py" in save
545. force_update=force_update, update_fields=update_fields)
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/django/db/models/base.py" in save_base
582. update_fields=update_fields, raw=raw, using=using)
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/django/dispatch/dispatcher.py" in send
185. response = receiver(signal=self, sender=sender, **named)
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/imagekit/specs/sourcegroups.py" in receiver
33. fn(self, sender=sender, **kwargs)
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/imagekit/specs/sourcegroups.py" in post_save_receiver
97. attname)
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/imagekit/specs/sourcegroups.py" in dispatch_signal
112. signal.send(sender=source_group, source=file)
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/django/dispatch/dispatcher.py" in send
185. response = receiver(signal=self, sender=sender, **named)
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/imagekit/registry.py" in source_group_receiver
111. self._source_groups[source_group]]
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/imagekit/registry.py" in get
41. return generator(**kwargs)
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/imagekit/specs/__init__.py" in __init__
88. super(ImageSpec, self).__init__()
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/imagekit/specs/__init__.py" in __init__
38. self.cachefile_backend = self.cachefile_backend or get_default_cachefile_backend()
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/imagekit/cachefiles/backends.py" in get_default_cachefile_backend
19. return get_singleton(settings.IMAGEKIT_DEFAULT_CACHEFILE_BACKEND,
File "HOME_DIR/.virtualenvs/prototyp_stb/lib/python2.7/site-packages/django/conf/__init__.py" in __getattr__
55. return getattr(self._wrapped, name)
Exception Type: AttributeError at /verwaltung/produkte/uploads/160/
Exception Value: 'Settings' object has no attribute 'IMAGEKIT_DEFAULT_CACHEFILE_BACKEND'
Request information:
GET: No GET data
POST: No POST data
FILES:
files[] = <InMemoryUploadedFile: nike-capri-si-so551076-2-0.jpg (image/jpeg)>
COOKIES:
csrftoken = 'fIrbO2XVDnE3rBKRmHFeaM1QrrhgRcpb'
sessionid = 'v2czmbi4esniso80bnoramokom2uhods'
messages = 'ef5f51d01dacbb65f19bd9581a9d335f8de455ee$[["__json_message",0,25,"You have signed out."]]'
That is the trace. I replaced my home-dir path by hand, because it does not have to be online ;).
When i set the settings manually, i'm always asked for the next setting to set.
I hope you can help me with this.
Thanks!
Thanks for the reply. We should definitely be able to figure this out!
First, can you check which versions of IK and appconf you're running?
import appconf; import imagekit; print appconf.__version__; print imagekit.__version__
Second, are you doing anything different than normal in your settings file? For example, are you importing ImageKit or some other package that might cause ImageKit to be imported?
The setting that's causing the error is given a default value that appconf should be adding to your settings object. The fact that it's not there probably means appconf isn't doing its thing for some reason.
I'm running into a very similar issue. In my development machine there's no issue but on my actual server I get asked for a ton of settings that should be set by default.
import appconf; import imagekit; print appconf.__version__; print imagekit.__version__
0.6
3.0.4
If I set all the settings that are required, basically filling in the defaults like so: http://django-imagekit.readthedocs.org/en/latest/configuration.html
I can then run
python manage.py generateimages
Which produces a series of
FAILED: 'NoneType' object has no attribute 'startswith'
By the way, I'm using django-storages on my server and storing all my images on Amazon S3.
If I try to run instance.my_spec.generate()
I get this:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/oneprovider/.virtualenvs/giaola/lib/python2.6/site-packages/imagekit/cachefiles/__init__.py", line 93, in generate
self.cachefile_backend.generate(self, force)
File "/home/oneprovider/.virtualenvs/giaola/lib/python2.6/site-packages/imagekit/cachefiles/backends.py", line 108, in generate
self.generate_now(file, force=force)
File "/home/oneprovider/.virtualenvs/giaola/lib/python2.6/site-packages/imagekit/cachefiles/backends.py", line 94, in generate_now
if force or self.get_state(file) not in (CacheFileState.GENERATING, CacheFileState.EXISTS):
File "/home/oneprovider/.virtualenvs/giaola/lib/python2.6/site-packages/imagekit/cachefiles/backends.py", line 68, in get_state
exists = self._exists(file)
File "/home/oneprovider/.virtualenvs/giaola/lib/python2.6/site-packages/imagekit/cachefiles/backends.py", line 112, in _exists
or file.storage.exists(file.name))
File "/home/oneprovider/.virtualenvs/giaola/lib/python2.6/site-packages/storages/backends/s3boto.py", line 410, in exists
name = self._normalize_name(self._clean_name(name))
File "/home/oneprovider/.virtualenvs/giaola/lib/python2.6/site-packages/storages/backends/s3boto.py", line 341, in _normalize_name
name)
SuspiciousOperation: Attempted access to 'https:/giaola-stage.s3.amazonaws.com/CACHE/images/profile_photos/IMG_1296/79dbd0ac5ebf734a8d394d147239b671.jpg' denied.
@bill-pairaktaridis Do you know what's different between your dev and production servers? Also, are you doing anything special in your settings file, like importing packages?
Can you verify that ImageKit's conf.py is being loaded; for example, by adding a print statement to it and then running the command?
Please do all troubleshooting without overriding the defaults.
Thanks!
@matthewwithanm Well, for one thing my dev is serving all files locally and my production is serving them from S3 via django-storages. So, I have this in a condition in my settings file:
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
I only import very few things in my settings.py
from django.core.urlresolvers import reverse_lazy
import djcelery
import sys
import os
import socket
I'll try to see if conf.py is being loaded and come back to you
EDIT: OK, it definitely loads conf.py. Here's my output:
Imagekit Conf.py #This is what I printed
Validating generator: giaola:giaolaprofile:profile_image_big #This is one of my ImageSpecFields
AttributeError: 'Settings' object has no attribute 'IMAGEKIT_DEFAULT_CACHEFILE_BACKEND'
Have someone tried importing the settings in a manage.py shell and tried accessing the values from there?
Any ideas on this issue?
Sorry, I was waiting for a reply from you. (GitHub doesn't notify people when you edit a message.)
Can you add a print statement at the end of conf.py as well as the beginning?
Sorry we have to go through this step by step like this but I still can't reproduce it. If anybody can put together a minimal test case, that would be most helpful.
Beginning conf.py
Ending conf.py
Validating generator: giaola:giaolaprofile:profile_image_big
AttributeError: 'Settings' object has no attribute 'IMAGEKIT_DEFAULT_FILE_STORAGE'
Could it be an import issue on my part? Maybe an issue with my Environment Variables?
And trying to save a new profile image I got this:
AttributeError: 'Settings' object has no attribute 'IMAGEKIT_CACHEFILE_NAMER'
in my log.
Shouldn't the code here:
def get_default_cachefile_backend():
"""
Get the default file backend.
"""
from django.conf import settings
return get_singleton(settings.IMAGEKIT_DEFAULT_CACHEFILE_BACKEND,
'file backend')
cause an error if that doesn't exist in settings?
I tried running
instance.my_spec.generate()
again without overriding any of the defaults and all I got was
Traceback (most recent call last):
File "<console>", line 2, in <module>
File "/home/oneprovider/.virtualenvs/giaola/lib/python2.6/site-packages/imagekit/models/fields/utils.py", line 15, in __get__
spec = self.field.get_spec(source=source)
File "/home/oneprovider/.virtualenvs/giaola/lib/python2.6/site-packages/imagekit/specs/__init__.py", line 242, in get_spec
return generator_registry.get(self.spec_id, source=source)
File "/home/oneprovider/.virtualenvs/giaola/lib/python2.6/site-packages/imagekit/registry.py", line 41, in get
return generator(**kwargs)
File "/home/oneprovider/.virtualenvs/giaola/lib/python2.6/site-packages/imagekit/specs/__init__.py", line 88, in __init__
super(ImageSpec, self).__init__()
File "/home/oneprovider/.virtualenvs/giaola/lib/python2.6/site-packages/imagekit/specs/__init__.py", line 38, in __init__
self.cachefile_backend = self.cachefile_backend or get_default_cachefile_backend()
File "/home/oneprovider/.virtualenvs/giaola/lib/python2.6/site-packages/imagekit/cachefiles/backends.py", line 19, in get_default_cachefile_backend
return get_singleton(settings.IMAGEKIT_DEFAULT_CACHEFILE_BACKEND,
File "/home/oneprovider/.virtualenvs/giaola/lib/python2.6/site-packages/django/conf/__init__.py", line 54, in __getattr__
return getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'IMAGEKIT_DEFAULT_CACHEFILE_BACKEND'
If I set all the missing variables as follows:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
IMAGEKIT_DEFAULT_CACHEFILE_BACKEND = 'imagekit.cachefiles.backends.Async'
IMAGEKIT_DEFAULT_FILE_STORAGE = DEFAULT_FILE_STORAGE
IMAGEKIT_CACHE_PREFIX = 'imagekit_'
IMAGEKIT_CACHEFILE_NAMER = 'imagekit.cachefiles.namers.hash'
IMAGEKIT_SPEC_CACHEFILE_NAMER = 'imagekit.cachefiles.namers.source_name_as_path'
IMAGEKIT_CACHEFILE_DIR = MEDIA_URL + 'cache/images'
I can at least run it but I get a long output of basically:
FAILED: 'Settings' object has no attribute 'IMAGEKIT_USE_MEMCACHED_SAFE_CACHE_KEY'
interspersed with my image urls...
If it's any help, this is installed on my virtual environment:
BeautifulSoup==3.2.1
Collectfast==0.1.11
Django==1.5.4
Fabric==1.7.0
Jinja2==2.7.1
Markdown==2.3.1
MarkupSafe==0.18
MySQL-python==1.2.4
Pillow==2.1.0
PyYAML==3.10
Pygments==1.6
South==0.8.2
Sphinx==1.2b1
Unidecode==0.04.14
Werkzeug==0.9.4
amqp==1.0.13
anyjson==0.3.3
argparse==1.2.1
beautifulsoup4==4.3.2
billiard==2.7.3.32
boto==2.21.0
celery==3.0.22
django-achievements==0.1.1
django-activity-stream==0.4.5beta1
django-announce==0.1.5
django-appconf==0.6
django-blog-zinnia==0.12.3
django-breadcrumbs==1.1.3-p1
django-celery==3.0.21
django-compressor==1.3
django-debug-toolbar==1.0
django-dowser==0.1.3
django-extensions==1.1.1
django-facebook==5.2.9
django-fields==0.2.2
django-filebrowser==3.5.2
django-filter==0.7
django-grappelli==2.4.8
django-hosts==0.6
django-htmlmin==0.6.3
django-imagekit==3.2
django-ios-notifications==0.1.5
django-jsonfield==0.9.10
django-mediagenerator==1.11
django-modeltranslation==0.6.1
django-mptt==0.5.5
django-oauth2-provider==0.2.6
django-ratings==0.3.7
django-redis-cache==0.10.0
django-redis-sessions==0.4.0
django-registration==1.0
django-registration-email==0.5.4
django-report-builder==1.11
django-reversion==1.8.0
django-rosetta==0.7.2
django-s3-folder-storage==0.2
django-ses==0.4.1
django-storages==1.1.8
django-tagging==0.3.1
django-tinymce==1.5.1
django-twilio==0.4
django-uuidfield==0.4.0
django-xmlrpc==0.1.5
djangorestframework==2.3.7
djazator==0.2.4
docutils==0.11
html5lib==0.99
httplib2==0.8
jingo==0.6.1
johnny-cache==1.4
kombu==2.5.13
librabbitmq==1.0.1
nose==1.3.0
openpyxl==1.6.2
paramiko==1.11.0
pilkit==1.1.6
py-bcrypt==0.3
pyOpenSSL==0.13
pycrypto==2.6
pyparsing==1.5.7
python-dateutil==2.1
python-memcached==1.53
pytz==2013.7
pyzmq==2.2.0.1
redis==2.8.0
requests==1.2.3
selenium==2.37.2
shortuuid==0.4
simplejson==3.3.0
six==1.4.1
sqlparse==0.1.10
stripe==1.9.3
twilio==3.5.1
unittest2==0.5.1
wsgiref==0.1.2
@bill-pairaktaridis Hey, what are you using to run your Django project? gunicorn, Apache?
Apache with mod_wsgi
On Thu, Jan 9, 2014 at 2:32 PM, Jannis Leidel [email protected]:
@bill-pairaktaridis https://github.com/bill-pairaktaridis Hey, what are you using to run your Django project? gunicorn, Apache?
— Reply to this email directly or view it on GitHubhttps://github.com/matthewwithanm/django-imagekit/issues/251#issuecomment-31926441 .
@bill-pairaktaridis Okay, can you do the following:
from imagekit.conf import ImageKitConf
ik_conf = ImageKitConf()
print ik_conf.configured_data
print ik_conf._meta.__dict__
best in the actual running server somewhere
>>> print ik_conf.configured_data
{'CACHE_BACKEND': 'default', 'CACHEFILE_DIR': 'CACHE/images', 'DEFAULT_CACHEFILE_BACKEND': 'imagekit.cachefiles.backends.Simple', 'CACHEFILE_NAMER': 'imagekit.cachefiles.namers.hash', 'USE_MEMCACHED_SAFE_CACHE_KEY': True, 'DEFAULT_CACHEFILE_STRATEGY': 'imagekit.cachefiles.strategies.JustInTime', 'SPEC_CACHEFILE_NAMER': 'imagekit.cachefiles.namers.source_name_as_path', 'CACHE_PREFIX': 'imagekit:', 'DEFAULT_FILE_STORAGE': 'storages.backends.s3boto.S3BotoStorage'}
>>> print ik_conf._meta.__dict__
{'holder_path': 'django.conf.settings', 'required': [], 'configured_data': {'CACHE_BACKEND': 'default', 'CACHEFILE_DIR': 'CACHE/images', 'DEFAULT_CACHEFILE_BACKEND': 'imagekit.cachefiles.backends.Simple', 'CACHEFILE_NAMER': 'imagekit.cachefiles.namers.hash', 'USE_MEMCACHED_SAFE_CACHE_KEY': True, 'DEFAULT_CACHEFILE_STRATEGY': 'imagekit.cachefiles.strategies.JustInTime', 'SPEC_CACHEFILE_NAMER': 'imagekit.cachefiles.namers.source_name_as_path', 'CACHE_PREFIX': 'imagekit:', 'DEFAULT_FILE_STORAGE': 'storages.backends.s3boto.S3BotoStorage'}, 'prefix': 'imagekit', 'proxy': False, 'defaults': {'IMAGEKIT_SPEC_CACHEFILE_NAMER': 'imagekit.cachefiles.namers.source_name_as_path', 'IMAGEKIT_DEFAULT_CACHEFILE_BACKEND': 'imagekit.cachefiles.backends.Simple', 'IMAGEKIT_DEFAULT_FILE_STORAGE': None, 'IMAGEKIT_CACHEFILE_NAMER': 'imagekit.cachefiles.namers.hash', 'IMAGEKIT_CACHE_BACKEND': None, 'IMAGEKIT_CACHEFILE_DIR': 'CACHE/images', 'IMAGEKIT_USE_MEMCACHED_SAFE_CACHE_KEY': True, 'IMAGEKIT_CACHE_PREFIX': 'imagekit:', 'IMAGEKIT_DEFAULT_CACHEFILE_STRATEGY': 'imagekit.cachefiles.strategies.JustInTime'}, 'holder': <django.conf.LazySettings object at 0x238f5d0>, 'names': {'CACHE_BACKEND': 'IMAGEKIT_CACHE_BACKEND', 'CACHEFILE_DIR': 'IMAGEKIT_CACHEFILE_DIR', 'DEFAULT_CACHEFILE_BACKEND': 'IMAGEKIT_DEFAULT_CACHEFILE_BACKEND', 'CACHEFILE_NAMER': 'IMAGEKIT_CACHEFILE_NAMER', 'SPEC_CACHEFILE_NAMER': 'IMAGEKIT_SPEC_CACHEFILE_NAMER', 'DEFAULT_CACHEFILE_STRATEGY': 'IMAGEKIT_DEFAULT_CACHEFILE_STRATEGY', 'USE_MEMCACHED_SAFE_CACHE_KEY': 'IMAGEKIT_USE_MEMCACHED_SAFE_CACHE_KEY', 'CACHE_PREFIX': 'IMAGEKIT_CACHE_PREFIX', 'DEFAULT_FILE_STORAGE': 'IMAGEKIT_DEFAULT_FILE_STORAGE'}}
I run it with python manage.py shell
In case it helps someone -- I saw this syndrome after I knowingly introduced a circular reference into settings.py
. I suspect the rootcause is somewhere in the bowels of Django settings evaluation, but it wasn't worth diagnosing further.
I suggest auditing your settings.py
for any non-trivial import
s.
Any news on this issue? I have the same problem and can't figure out what's wrong. I have no non-trivial imports in settings.py.
@russian-master Sorry, I'm not sure since I can't reproduce it. Are you able to put together a small project that exhibits the issue?
@jezdez Does @bill-pairaktaridis's information tell you anything? (Thanks for jumping in BTW)
I coudn't resolve the issue and even understand what was the cause. So I switched to another solution. My app has changed greatly since then and I'm afraid I can't make demo project, sorry.
I ran in this issue today.
I have a project which has for some customers special functionality. This is realized by an env-var which then in a modified settings.py loads additional code, structured as a module. It looks like this:
CUSTOM_MODULE = 'project.customers.' + custom_module # custom_module is some string, like 'feature_x'
module = __import__(CUSTOM_MODULE, globals(), locals(), ['*'])
# Add customer specific module settings
CUSTOM_MODULE_SETTINGS = module.SETTINGS
If this code path executes, Imagekit doesn't find its default settings.
Followup: Digging deeper, the main issue is that a custom module imported a model in which ImageKit were used. So I guess there's the crux of the matter.
Followup: I managed to optimize the imports by moving them into the methods where they are needed. So they are not re-imported at the settings-initialize-time. This fixed my issue.
I'm also getting this issue now... very strange.
From what I read in the comments I think that the problem is caused by some imports in project's settings.
@joshuairl did you have any imports in your settings module and if any can you show them to us?
I have the same problem and the cause was an import imagekit
in settings.py
.
I have some optional apps and I add an application if a specific import do not fail; I have solved using imp without importing the module.
@pat1 this is the exact problem that others are facing. The reason is because we import a lot of stuff in imagekit/__init__.py
. Some of these import is causing probably Django to get some value from settings
but they are currently in process of configuring.
@pat1 can you post your workaround here in order to be helpfull for others trying the same thing?
@joshuairl as I asked you already but can you tell us if you have any imports in your settings
and more precisely import imagekit
?
@liquidscorpio @bill-pairaktaridis I know that it was long ago, but did you have any import imagekit
in your settings
?
I have the same problem and not import imagekit in settings...
>>> import appconf; import imagekit; print appconf.__version__; print imagekit.__version__
1.0.2
3.2.7
python v2.7 Django v1.8.18
@jedie and did you have any other imports in settings? If you have which one? When dis happens - when running trough manage.py
or when running trough some WSGI server (like uwsgi, gunicorn or apache mod_wsgi)?
did you have any other imports in settings?
Yes i have imports in settings. But IMHO they are not related to imagekit...
I added a traceback.print_stack()
in imagekit/init.py to see the first import.
Think it's ok: The normal app loading. (Django version 1.8.18)
This output is from ./manage.py runserver
File "./manage.py", line 23, in <module>
execute_from_command_line(sys.argv)
File ".../.venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File ".../.venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 317, in execute
autoreload.check_errors(django.setup)()
File ".../.venv/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 229, in wrapper
fn(*args, **kwargs)
File ".../.venv/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File ".../.venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File ".../.venv/local/lib/python2.7/site-packages/django/apps/config.py", line 86, in create
module = import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File ".../.venv/local/lib/python2.7/site-packages/imagekit/__init__.py", line 5, in <module>
traceback.print_stack()
EDIT: Think it's related to pytest run!
Verry strange. What version of Django and ImageKit are you using?
$ pip freeze
...
Django==1.8.18
django-appconf==1.0.2
django-appdata==0.2.0
...
django-imagekit==3.2.7
...
Pillow==2.9.0
...
pytest==3.4.1
pytest-cov==2.5.1
pytest-django==3.1.2
...
Think it's related to my setup, see also: https://github.com/django-compressor/django-appconf/issues/30
Maybe something like https://github.com/julen/django-statici18n/commit/7638920e7be8247857fad36b422d977bcac3cf60 is a possible solution?!?
Sorry that I didn't saw the versions of django and imagekit in your previous comments. I see that you are not using the latest version of imagekit. From the version s that you are using I can conclude that the project is not new and probably it was worked in the past but now is broken.
You can try to bisect your project and see when this happend in order to see what is the couse. You also can try to upgrade to the latest ImageKit (4.0.2) before everything to see if the problem still exists.
If nothing helps can you try to see if adding and AppConf
(as in linked commit in django-statici18n) is helping in your case? If it is helping can you prepare a PR?
thanks for your support.
I updated to last version: doesn't help I added a "apps.py": doesn't help
But i change a little bit the pytest run and now it's: AttributeError: 'Settings' object has no attribute 'ALDRYN_SEARCH_CMS_PAGE'
So i assume it's not related to django-imagekit Think it's a pytest-django <-> django-appconf thing, in combination with my project setup...
EDIT: It happens to me in test classmethod setUpTestData()
I didn't find a real solution. So i just do the work-a-round and add the settings in my settings.py
EDIT2: I open https://github.com/django-compressor/django-appconf/issues/41 for this, too.
It's very hard to figure out what's really the problem is :(
It's depend on the pytest running order... And happens not with all apps that used django-appconf...
It only happens in the tests. That's why I have another solution. Because I want to keep my settings clean:
My currently new work-a-round is a pytest.fixture(autouse=True)
and fill django settings with app-config settings manually, see: https://gist.github.com/jedie/c119e73d8e7dad48183f9622b430373f
I got the same using:
django-imagekit==4.0.2
Django==2.1.1
djangorestframework==3.8.2
To get going, adding these settings fixed it for me (I assume you need all of them if you intend to you use more functionality of imagekit):
# this are default values from imagekit that are somehow not picked up
IMAGEKIT_DEFAULT_CACHEFILE_BACKEND = 'imagekit.cachefiles.backends.Simple'
IMAGEKIT_CACHEFILE_NAMER = 'imagekit.cachefiles.namers.hash'
IMAGEKIT_CACHEFILE_DIR = 'CACHE/images'
IMAGEKIT_DEFAULT_FILE_STORAGE = DEFAULT_FILE_STORAGE
IMAGEKIT_CACHE_PREFIX = 'imagekit:'
IMAGEKIT_USE_MEMCACHED_SAFE_CACHE_KEY = True
IMAGEKIT_CACHE_BACKEND = 'default'
IMAGEKIT_CACHE_TIMEOUT = None