Django Not Found: /static/admin/css/login.css

出現問題:

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後臺就正常了


————————————————
鏈接:https://blog.csdn.net/Miss_Audrey/article/details/81134428

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章