我遇到了Dajaxice的问题,以及它是如何创建用于Ajax的自定义JavaScript文件的。当安装Dajaxice运行manage.py collectstatic
时,它会创建一个自定义JavaScript文件。 This post也引用此问题。在我的情况下运行:dajaxice collectstatic创建临时文件
python manage.py findstatic dajaxice/dajaxice.core.js
给出:
Found 'dajaxice/dajaxice.core.js' here:
/private/var/folders/dp/yw0xd2f52yg7qmt992s72_9r0000gn/T/tmpRWRAGT
当本地运行。我遇到的问题是,当将它与django-storages配对并启动以提供来自Amazon S3的静态文件时,它会爆炸,因为该文件是通过引用绝对路径而不是相对路径创建的(我认为它不是相关路径django-storages不喜欢的东西)。错误看起来是这样的:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, 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 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 163, in handle_noargs
collected = self.collect()
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 113, in collect
handler(path, prefixed_path, storage)
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 290, in copy_file
source_path = source_storage.path(path)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/files/storage.py", line 82, in path
raise NotImplementedError("This backend doesn't support absolute paths.")
(在这种情况下,我部署在Heroku上,这就是为什么我不能只是手动复制创建的文件为静态位置,并引用它)。有没有解决的办法?我可以让Dajaxice将生成的文件放在相对路径位置吗?或者我可以通过迫使django-storages/boto接受绝对路径来绕过它吗?或者如果一切都失败了,当我收集静态文件时,是否有一种简单的方法来预先生成文件,而无需卸载所有的S3依赖项,将文件复制过来并迫使Dajax停止查找生成的文件?
任何帮助表示赞赏。