Static file import in Django

1. Create a python package named static in the root directory of the django project , or in the app

2. Change the settings.py file of the project

STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
  • STATIC_URL = '/static/'The static is the alias of the absolute path of the static file, which is different from the package name static. The package name can be named arbitrarily. When calling static files, only aliases can be used .
  • The advantage of this is that the static in it can be changed at will with later changes, STATICFILES_DIRSand of course the corresponding package name should also be changed.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325326410&siteId=291194637