出现问题:
Not Found: /static/admin/css/login.css
Not Found: /static/admin/css/dashboard.css
Not Found: /static/admin/css/base.css
Not Found: /static/admin/css/responsive.css
Not Found: /static/admin/css/base.css
Not Found: /static/admin/css/dashboard.css
Not Found: /static/admin/css/responsive.css
————————————————
链接:https://blog.csdn.net/Miss_Audrey/article/details/81134428
原因:
缺失 /static/admin/
python manage.py collectstatic
/root/app/venv/lib/python3.6/site-packages/pymysql/_auth.py:8: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
from cryptography.hazmat.backends import default_backend
You have requested to collect static files at the destination
location as specified in your settings.
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel:
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
解决办法:
首先检查 mysite/settings.py 要有以下配置:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')
然后 urls.py 文件
from django.contrib import admin
from django.conf.urls import url,include
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
url(r'^admin/',admin.site.urls),
] + static(settings.STATIC_URL,document_root = settings.STATIC_ROOT)
在mysite里创建static目录,执行 python manage.py collectstatic (会自动把python里site-packages/django/contrib/admin/static/admin下的文件复制到static文件夹下,也可自己找到文件路径进行手动复制)
粘上uwsgi配置文件,以及nginx的配置
mysite.ini
[uwsgi]
master=true
chdir=/root/myproj/mysite/
module=mysite.wsgi
py-autoreload=1
lazy-apps=true
socket=127.0.0.1:8000
processes=2
buffer-size=32768
#daemonize=logs/uwsgi.log
log-maxsize = 5000000
vacuum = true
disable-logging = true
/etc/nginx/nginx.conf
在server里添加以下代码
location /static {
alias /root/myproj/mysite/static/;
}
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
}
最后运行 uwsgi -i mysite.ini 再访问admin后台就正常了