我有一个包含这些文件夹的项目,我想修复 runsever 命令与静态文件夹和管理区域的输出:
ETCD
我添加到urls.py中:
(env) [mythcat@desk mysite]$ tree -d
.
├── mysite
│ ├── __pycache__
│ └── static
│ ├── admin
│ │ ├── css
│ │ │ └── vendor
│ │ │ └── select2
│ │ ├── fonts
│ │ ├── img
│ │ │ └── gis
│ │ └── js
│ │ ├── admin
│ │ └── vendor
│ │ ├── jquery
│ │ ├── select2
│ │ │ └── i18n
│ │ └── xregexp
│ └── rest_framework
│ ├── css
│ ├── docs
│ │ ├── css
│ │ ├── img
│ │ └── js
│ ├── fonts
│ ├── img
│ └── js
└── test001
├── migrations
├── static
└── templates
└── test001
settings.py是使用应用程序和以下源代码设置的:
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
...
urlpatterns = [
...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += staticfiles_urlpatterns()
我用了这个:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
...
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates'),]
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
'/home/mythcat/projects/django/mysite/mysite/static/',
'/home/mythcat/projects/django/mysite/mysite/static/admin/',
'/home/mythcat/projects/django_chart/mysite/mysite/static/admin/css',
'/home/mythcat/projects/django/mysite/mysite/static/rest_framework/',]
但是我得到了这个错误:
(env) [mythcat@desk mysite]$ python3 manage.py collectstatic
...
177 static files copied to '/home/mythcat/projects/django_chart/mysite/mysite/static', 165 unmodified.