Django-Configurations导致我的STATIC_URL无效

时间:2014-07-29 14:29:13

标签: python django

我有一个django(1.6.5)项目,我正在使用django-configurations(0.8)包,我试图通过以下方式在settings.py文件中设置环境变量的STATIC_URL:

from configurations import Configuration, values
BUCKET_NAME = values.SecretValue()
STATIC_URL = 'https://s3.amazonaws.com/%s/' % BUCKET_NAME

但是STATIC_URL设置为:

'https://s3.amazonaws.com/<Value default:None>'

无效或有意。我也设置了正确的环境变量:DJANGO_BUCKET_NAME ='thekey'

任何帮助将不胜感激

2 个答案:

答案 0 :(得分:3)

我查看了django cookie cutter的问题并找到了这个解决方案:

https://github.com/burhan/cookiecutter-django/commit/c8ee217dd72ec29ccea4f683d83ca7438247461c

告诉我切换:

STATIC_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME

为:

STATIC_URL = 'https://s3.amazonaws.com/%s/' % (AWS_STORAGE_BUCKET_NAME.setup('DJANGO_AWS_STORAGE_BUCKET_NAME'),)

答案 1 :(得分:2)

问题是django-configurations中__repr__的{​​{1}}方法。 他们已经修复了这个问题,但没有更新pckage版本,所以pypy仍然引用了错误的版本。

v-0.8 vs updated version

解决方法是将Value设置为:

'https://s3.amazonaws.com/%s/' % (AWS_STORAGE_BUCKET_NAME.setup('AWS_STORAGE_BUCKET_NAME'),)

来源:https://github.com/burhan/cookiecutter-django/commit/c8ee217dd72ec29ccea4f683d83ca7438247461c