[英]Fields added to Django's AbstractUser aren't showing up in the migration
[英]Why aren't my images showing up after following Django's documentation on static files?
我在正在構建的網站中顯示圖像時遇到了一些問題。 我按照 Django static 文件文檔中的說明進行操作。 也就是說,我有:
settings.py
文件包含STATIC_URL = 'static/'
{% load static %}
<img src="{% static 'my_app/example.jpg' %}" alt="My image">
當我導航到相關頁面時,我沒有收到任何錯誤。 只是一個空的 div 圖像應該在哪里。
似乎在過去,這個問題已經通過使用render()
( 示例)解決了。 但是,我使用的是 Django 4.x,以及render()
function。
為什么我的圖片不顯示?
還有一個要求,那就是將 static url 設置添加到我們的urlpatterns
:
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
這來自同一文檔中的“在開發期間提供 static 文件”部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.