我在Heroku上部署了一个简单的Django应用程序。当我运行collectstatic
将静态文件上传到S3时,出现以下错误:
Traceback (most recent call last): File "appname/manage.py", line 11, in execute_from_command_line(sys.argv) File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line utility.execute() File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv self.execute(*args, **options.__dict__) File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute output = self.handle(*args, **options) File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 415, in handle return self.handle_noargs(**options) File "/app/.heroku/python/lib/python2.7/site-packages/collectfast/management/commands/collectstatic.py", line 135, in handle_noargs collected = self.collect() File "/app/.heroku/python/lib/python2.7/site-packages/collectfast/management/commands/collectstatic.py", line 33, in collect ret = super(Command, self).collect(*args, **kwargs) File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 111, in collect handler(path, prefixed_path, storage) File "/app/.heroku/python/lib/python2.7/site-packages/collectfast/management/commands/collectstatic.py", line 92, in copy_file self.destroy_lookup(prefixed_path) File "/app/.heroku/python/lib/python2.7/site-packages/collectfast/management/commands/collectstatic.py", line 61, in destroy_lookup cache.delete(self.get_cache_key(path)) File "/app/.heroku/python/lib/python2.7/site-packages/django/core/cache/backends/memcached.py", line 86, in delete self._cache.delete(key) _pylibmc.MemcachedError: error 47 from memcached_delete(:1:collectfast_asset_dc44a7965f7): SERVER HAS FAILED AND IS DISABLED UNTIL TIMED RETRY, host: 127.0.0.1:11211 -> libmemcached/connect.cc:592
在heroku上设置了以下env变量:
BUILDPACK_URL: DATABASE_URL: DJANGO_AWS_ACCESS_KEY_ID: DJANGO_AWS_SECRET_ACCESS_KEY: DJANGO_AWS_STORAGE_BUCKET_NAME: DJANGO_CONFIGURATION: DJANGO_SECRET_KEY: HEROKU_POSTGRESQL_CRIMSON_URL: MEMCACHIER_PASSWORD: MEMCACHIER_SERVERS: MEMCACHIER_USERNAME: PGBACKUPS_URL: SENDGRID_PASSWORD: SENDGRID_USERNAME:
我几天都在努力解决这个问题。昨天,我意识到其中一个env变量有一个拼写错误的副本。删除拼写错误的env变量后,collectstatic
命令工作正常,文件上传到S3。现在我正在使用另一个应用程序而无法让它工作。
已存在具有相同名称的空S3存储桶。我已经尝试过用户特定的和帐户范围的AWS凭证,但都没有工作。
答案 0 :(得分:0)
我遇到了同样的问题。我已回答了相关的GitHub issue。
为了完整性,这里是解决方案:
首先将django-pylibmc-sasl==0.2.4
添加到requirements.txt。
然后在settings.py中用以下内容替换文件末尾的“CACHING”部分:
########## CACHING
os.environ['MEMCACHE_SERVERS'] = os.environ.get('MEMCACHIER_SERVERS', '')
os.environ['MEMCACHE_USERNAME'] = os.environ.get('MEMCACHIER_USERNAME', '')
os.environ['MEMCACHE_PASSWORD'] = os.environ.get('MEMCACHIER_PASSWORD', '')
CACHES = {
'default': {
'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
'LOCATION': os.environ.get('MEMCACHIER_SERVERS', ''),
'TIMEOUT': 500,
'BINARY': True,
'OPTIONS': { 'tcp_nodelay': True }
}
}
########## END CACHING
它现在应该在Heroku上运行正常。