Introducing static into static files in django

Static file configuration

Simply put: Some packages that we import ourselves are called static file
configuration steps:

  • 1. Create a static package in the global first,
  • 2. Import our bootstrap in static, or jquery, etc...
  • 3. Then add some configuration in settings.py

settings.py file

STATIC_URL = '/static/'       #这个相当于给配置起的别名,如果这里的名字修改了就按照这里的名字去导入
STATICFILES_DIRS = [ 
  os.path.join(BASE_DIR, 'static')       #通过和项目根路径拼接得到static的路径
]     

If there are some static files, they are not linked to any app. That is, it is no longer in the directory of any app. Then you can add STATICFILES_DIRS in settings.py, and DTL will look for static files in the path of this list in the future. For example, we create a static folder in the same level directory of manage.py. Then add STATICFILES_DIRS in settings.py:

Guess you like

Origin blog.csdn.net/weixin_48154829/article/details/107835811