【发布时间】:2018-11-02 10:56:36
【问题描述】:
当我尝试发出命令来收集静态文件时
In [41]: ! python manage.py collectstatic
它抛出FileNotFoundError:
FileNotFoundError: [Errno 2] No such file or directory:
'/Users/me/Desktop/Django/forum/static'
然而,存在文件'/Users/me/Desktop/Django/forum/static'
In [44]: ! tree -L 2
.
├── db.sqlite3
├── forum
│ ├── __init__.py
│ ├── __pycache__
│ ├── settings.py
│ ├── static
│ ├── templates
│ ├── urls.py
│ └── wsgi.py
├── forums
│ ├── __init__.py
│ ├── __pycache__
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ ├── models.py
│ ├── static
│ ├── templates
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── ll_forum
│ ├── bin
│ ├── include
│ ├── lib
│ ├── pip-selfcheck.json
│ ├── pyvenv.cfg
│ └── share
└── manage.py
14 directories, 15 files
设置.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#my apps
"forums"
]
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"), #notice the comma
)
【问题讨论】:
-
@JuniorGantin 根据他的问题,这不是一个好的答案。
-
请注意,在将项目部署到生产环境之前,您不必设置
STATIC_ROOT或运行collectstatic。由于您的INSTALLED_APPS中有'django.contrib.staticfiles',因此runserver将负责为您提供静态文件。
标签: django