我想使用我的网络服务器提供静态文件。
当前安装的唯一应用程序是django.contrib.admin
,它包含一些我想要提供的静态文件。
./manage.py runserver
一切正常。静态文件正确提供。
但我无法运行./manage.py collectstatic
。
这就是我配置django.contrib.staticfiles
:
STATIC_ROOT
设置为可写的空目录。让我们称之为/var/www/SITE_NAME/static/
我已将其他所有内容保留为默认值:
STATIC_URL = '/static/'
STATICFILES_DIRS = ()
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
现在,当我尝试在应用程序文件夹中运行collectstatic
时,收到一条非常奇怪的错误消息:
$ ./manage.py collectstatic
You have requested to collect static files at the destination
location as specified in your settings file.
This will overwrite existing files.
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Copying '/usr/lib/pymodules/python2.7/django/contrib/admin/media/__init__.py'
Traceback (most recent call last):
File "./manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/lib/pymodules/python2.7/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/pymodules/python2.7/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/pymodules/python2.7/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/pymodules/python2.7/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/lib/pymodules/python2.7/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/usr/lib/pymodules/python2.7/django/contrib/staticfiles/management/commands/collectstatic.py", line 89, in handle_noargs
self.copy_file(path, prefixed_path, storage, **options)
File "/usr/lib/pymodules/python2.7/django/contrib/staticfiles/management/commands/collectstatic.py", line 199, in copy_file
shutil.copy2(source_path, full_path)
File "/usr/lib/python2.7/shutil.py", line 127, in copy2
copyfile(src, dst)
File "/usr/lib/python2.7/shutil.py", line 82, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 2] No such file or directory: u'/var/www/SITE_NAME/static/admin/__init__.py'
为什么会收到此错误消息?
似乎没有任何意义。
为什么它会在admin/__init__.py
中查找STATIC_ROOT
时只能复制此目录中的静态文件?
答案 0 :(得分:2)
嗯,这是由于我没有看到STATIC_ROOT目录的错误权限!