【发布时间】:2015-07-17 16:34:36
【问题描述】:
我正在尝试在 heroku 上运行收集我的静态文件,所以我运行了命令:
heroku run python manage.py collectstatic --noinput
我的设置文件是:
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
# define the directory which all upload files will be saved
PROJECT_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'MyApp/media/')
MEDIA_URL = '/MyApp/media/'
我收到以下错误消息:
OSError: [Errno 2] No such file or directory: '/app/MyApp/static'
这是什么意思?
为什么我应该在“/app/MyApp”中有一个“静态”文件?不应该是
STATIC_ROOT?
完整的追溯:
Running `python manage.py collectstatic --noinput` attached to terminal... up, r
un.9966
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/sitepackages/django/core/management/_
_init__.py", line 385, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/sitepackages/django/core/management/_
_init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/sitepackages/django/core/management/base.py",
line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/sitepackages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/sitepackages/django/core/management/base.py", line 533, in handle
return self.handle_noargs(**options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle_noargs
collected = self.collect()
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect
for path, storage in finder.list(self.ignore_patterns):
File "/app/.heroku/python/lib/python2.7/sitepackages/django/contrib/staticfiles/finders.py", line 111, in list
for path in utils.get_files(storage, ignore_patterns):
File "/app/.heroku/python/lib/python2.7/sitepackages/django/contrib/staticfiles/utils.py", line 27, in get_files
directories, files = storage.listdir(location)
File "/app/.heroku/python/lib/python2.7/sitepackages/django/core/files/storage.py", line 270, in listdir
for entry in os.listdir(path):
OSError: [Errno 2] No such file or directory: '/app/CTFdj/static'
编辑: OSError: [Errno 2] 没有这样的文件或目录:'/app/CTFdj/static' =>>
OSError: [Errno 2] 没有这样的文件或目录:'/app/MyApp/static'
【问题讨论】:
-
请显示完整的回溯。
-
您的
STATIC_ROOT错误。它应该是收集的静态目录的服务路径。 -
什么意思?我的 STATIC_ROOT 声明不是意味着我的文件将在“staticfiles”目录下的主项目目录中提供吗?你能给我一个好的声明的例子吗?
-
@brad,我想我不应该说错,因为它也可能有效,但我不确定拥有 相对路径 的效果。文档说它应该是绝对路径