1

我想使用我的网络服务器提供静态文件。

当前安装的唯一一个应用程序是django.contrib.admin,它包含一些我想提供的静态文件。

一切正常./manage.py runserver。静态文件正确提供。

但我无法运行./manage.py collectstatic

这就是我的配置方式django.contrib.staticfiles

  1. 我设置STATIC_ROOT了一个可写的空目录。让我们称之为/var/www/SITE_NAME/static/
  2. 我已将其他所有内容保留为默认值:

    STATIC_URL = '/static/'
    STATICFILES_DIRS = ()
    STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
        'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    )
    
  3. 现在,当我尝试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

4

1 回答 1

2

好吧,这是由于我没有看到的 STATIC_ROOT 目录的错误权限!

于 2011-11-13T00:33:58.347 回答