1
我想使用我的Web服務器提供靜態文件。Django collectstatic無法訪問STATIC_ROOT中的admin/__ init__.py
當前安裝的唯一應用程序是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'
爲什麼我會收到此錯誤消息?
它似乎沒有任何意義。
爲什麼它會在STATIC_ROOT
中尋找admin/__init__.py
當它應該只是複製靜態文件在這個目錄?
嗯,這是由於'STATIC_ROOT'目錄的權限不好,我沒有看到! 我仍然不明白爲什麼這樣一個誤導性的錯誤信息,爲什麼'collectstatic'也複製'__init __。py'和'__init __。pyc'文件。 爲什麼這些文件也被複制?他們不是靜態文件! – alexpirine