在python manage.py runserver 前单独测试html文件有css样式,但是运行后系统不能加载css。
解决方法一共有两个:
方法一:
1.配置settings文件
STATIC_URL = '/static/' STATIC_ROOT = os.path.join( BASE_DIR, 'static') STATICFILES_DIR= ( os.path.join(BASE_DIR,'static'), ) STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', # 'django.contrib.staticfiles.finders.DefaultStorageFinder', )
2运行:
python manage.py collectstatic
最后可以看到问题已解决
过了几天后发现又出问题了,于是又弄了半天
方法二:
第一步:同方法一第一步配置settings
第二步:在html文件里加
{% load static %}
如下:
第三步:修改link css文件的写法
最后运行项目发现还是不行,于是想了一下,把浏览器数据清除一下发现问题解决了
我用的是google,->设置->高级设置->清除浏览器数据。