我正在运行命令python manage.py collectstatic
You have requested to collect static files at the destination
location as specified in your settings:
/static
python manage.py collectstatic
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
错误即时通讯; 无法打开文件“/static/fonts/FreeSans.ttf”
Copying '/home/mark/Desktop/xls/python-django-exporting-files/static/js/bootstrap.min.js'
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle
collected = self.collect()
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 107, in collect
handler(path, prefixed_path, storage)
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 315, in copy_file
self.storage.save(prefixed_path, source_file)
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/core/files/storage.py", line 64, in save
name = self._save(name, content)
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/core/files/storage.py", line 223, in _save
os.makedirs(directory)
File "/home/mark/.virtualenvs/test/lib/python2.7/os.py", line 150, in makedirs
makedirs(head, mode)
File "/home/mark/.virtualenvs/test/lib/python2.7/os.py", line 157, in makedir
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/static'
浏览器中出现的错误;
Can't open file "/static/fonts/FreeSans.ttf"
TTFError at /
Can't open file "/static/fonts/FreeSans.ttf"
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.8.2
Exception Type: TTFError
Exception Value:
Can't open file "/static/fonts/FreeSans.ttf"
答案 0 :(得分:2)
STATIC_ROOT = os.path.join(BASE_DIR, '/static/')
应该是:
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
/
重置树,它会在根目录中查找静态目录,即字面上:/static
您想要/home/user/project/static
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
STATICFILES_DIRS = ( "/home/mark/Desktop/xls/python-django-exporting-files/static", )
try:
from local_settings import *
except:
pass
STATICFILES_DIRS
是您保留自己应使用collectstatic
收集的静态文件的地方。它不能与STATIC_ROOT相同。
您的静态结构可能就像
DJANGO_PROJECT_DIR
|--> PROJECT_DIR
|----> settings.py
|----> templates
|----> static
|--> static
|--> manage.py
然后代码将(用项目目录名替换PROJECT_DIR):
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'PROJECT_DIR', 'static'), )
try:
from local_settings import *
except:
pass