我无法获取图片:
我已经签入了settings.py 文件和html 文件。一切都很好,但不起作用。我该如何解决这个问题?文件和CSS文件的路径一切正常。我还检查了代码,但一切都很好。检查告诉我该文件不存在,但它确实存在。
按照步骤操作
# -------- handle Static Files In Django --------
# Steps:
# 1 - Create (static) folder in Root Directory of Project
# 2 - Paste Your Static Files Folder in (static) Folder (js,css,images...etc)
# 3 - Now Do Setting in (setting.py)
STATIC_URL = '/static/'
STATICFILES_DIRS = [BASE_DIR / 'static']
# 4 - add {% load static %} tag on top of html page
# 5 - Now use ({% static 'assets/image.jpg' %}) tag in HTML File for calling static files
# 6 - Done
写在模板的顶部
{% load static %}
然后使用
{% static 'img/myimage.png' %}
来寻址您的文件。