参考文档: https://docs.djangoproject.com/en/1.9/howto/static-files/
- settings.py文件,确保引入 django.contrib.staticfiles
INSTALLED_APPS = [
...
'django.contrib.staticfiles',
...
]
- settings.py文件,定义STATIC_URL及STATICFILES_DIRS
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
- 在模板中,使用格式如
{% load staticfiles %}
<img src="{% static "my_app/myexample.jpg" %}" alt="My image"/>