【问题标题】:Django collectstatic fails trying to access admin/__init__.py in STATIC_ROOTDjango collectstatic 尝试访问 STATIC_ROOT 中的 admin/__init__.py 失败
【发布时间】:2011-12-27 10:37:52
【问题描述】:

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

当前安装的唯一一个应用程序是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'
    

为什么我会收到此错误消息?

这似乎没有任何意义。

当它应该只复制此目录中的静态文件时,为什么要在STATIC_ROOT 中寻找admin/__init__.py

【问题讨论】:

  • 嗯,是因为STATIC_ROOT 目录的权限不好,我没看到!我仍然不明白为什么会有这样一个误导性的错误消息,为什么collectstatic 也会复制__init__.py__init__.pyc 文件。为什么这些文件也被复制了?它们不是静态文件!

标签: django django-admin django-staticfiles


【解决方案1】:

嗯,原来是我没看到的STATIC_ROOT目录权限不好!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-22
    • 1970-01-01
    • 2015-11-03
    • 2012-11-07
    • 2011-07-08
    • 1970-01-01
    • 2016-04-18
    • 2020-08-16
    相关资源
    最近更新 更多