当我试图发出命令来收集静态文件时
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/论坛/静态’。
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 filesThe setting.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
)发布于 2018-05-23 12:43:00
您应该在设置中提供STATIC_ROOT,默认情况下Django在根项目中查找名为static的目录,这就是为什么您的get文件夹不存在的原因。
您的设置旁边有一个目录static,它不应该在那里。顺便说一句,您的模板也不应该在那里。
将它们移回根项目。
├── db.sqlite3
├── forum
│ ├── __init__.py
│ ├── __pycache__
│ ├── settings.py
| |---static # remove this
│ ├── templates # remove this here
│ ├── urls.py
│ └── wsgi.py
|---static -- # GOOD
|---templates # GOOD发布于 2018-05-23 12:44:38
您需要在Django应用程序外部拥有静态目录。这个目录和Django应用程序应该是分开的。
然后,如果您指定:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"), #notice the comma
)这意味着静态目录位于基目录中。或者你只有forum,forums,ll_forum .
如果您想绝对地将静态目录保存在Django应用程序中,请在BASE_DIR中创建这个目录(从初始位置移动到基本项目),并在settings.py文件中编写如下内容:
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static"),]
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static/')最后,您应该有这样的东西:
.
├── 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
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── ll_forum
│ ├── bin
│ ├── include
│ ├── lib
│ ├── pip-selfcheck.json
│ ├── pyvenv.cfg
│ └── share
└── manage.py
│
└── static
│
└── templateshttps://stackoverflow.com/questions/50488586
复制相似问题