Django静态图像显示然后不显示,视图共享静态徽标图像所在的基本Html文件

Django静态图像显示然后不显示,视图共享静态徽标图像所在的基本Html文件,django,django-views,django-templates,Django,Django Views,Django Templates,djangoprojectdir/static/media/文件夹中的我的徽标显示在我的主页上,但没有显示在我的其他视图中。我不知道为什么它没有出现在其他页面上,因为它与导航栏和标题共享相同的base.html文件。目前在数字海洋、nginx、gunicorn上托管正在制作的网站。我只是尝试在没有数据库的小项目中调试静态文件。我已经收集了静态数据。该图像仅适用于我的IndexView。我的其他与我的对象相关的静态图像文件似乎渲染良好。我一直在竭尽全力想办法解决这个问题 base.html中有问题

djangoprojectdir/static/media/文件夹中的我的徽标显示在我的主页上,但没有显示在我的其他视图中。我不知道为什么它没有出现在其他页面上,因为它与导航栏和标题共享相同的base.html文件。目前在数字海洋、nginx、gunicorn上托管正在制作的网站。我只是尝试在没有数据库的小项目中调试静态文件。我已经收集了静态数据。该图像仅适用于我的IndexView。我的其他与我的对象相关的静态图像文件似乎渲染良好。我一直在竭尽全力想办法解决这个问题

base.html中有问题的图像代码是:

  <a class="navbar-brand" href="{% url 'maps:index' %}"><img src="static/media/Dirt logo3.png" hieght="5" class="img-fluid" alt="Responsive image"> </a>

Views.py

# works on IndexView but not any other view
class IndexView(generic.ListView):
    template_name = 'maps/index.html'
    paginate_by = 20
    def get_queryset(self):
        return Location.objects.all()

    context_object_name = 'location'

class NeeddirtView(generic.ListView):
    template_name = 'maps/needdirt.html'
    paginate_by = 20
    def get_queryset(self):
        return Location.objects.all()

    context_object_name = 'location'

从maps/url.py

from django.urls import path
from . import views
from django.conf import settings
from django.conf.urls.static import static


app_name = 'maps'

urlpatterns = [
    # /maps/
    path('', views.IndexView.as_view(), name='index'),
    # /maps/71/
    path('<int:pk>/', views.DetailView.as_view(), name='detail'),
    path('register/', views.UserFormView.as_view(), name='register'),
    path('login/', views.LoginView.as_view(), name='login'),
    path('logout/', views.LogoutView.as_view(), name='logout'),
    # /maps/companies/
    path('companies/', views.CompView.as_view(), name='comp'),
    # /maps/equipment/
    path('equipment/', views.EquipView.as_view(), name='equip'),
    #maps/
    path('equipment/<int:pk>/', views.EquipdetView.as_view(), name='equipdet'),
    path('location/add/', views.LocationCreate.as_view(), name='location-add'),
    path('location/<int:pk>/', views.LocationCreate.as_view(), name='location-update'),
    path('location/<int:pk>/delete/', views.LocationDelete.as_view(), name='location-delete'),
    path('equipment/add/', views.EquipCreate.as_view(), name='equipment-add'),
    path('equipment/<int:pk>/', views.EquipCreate.as_view(), name='equipment-update'),
    path('equipment/<int:pk>/delete/', views.EquipDelete.as_view(), name='equipment-delete'),
    path('quarry/', views.QuarryView.as_view(), name='quarry'),
    path('quarry/<int:pk>/', views.QuarrydetView.as_view(), name='quarrydet'),
    path('quarry/add/', views.QuarryCreate.as_view(), name='quarry-add'),
    path('quarry/<int:pk>/', views.QuarryCreate.as_view(), name='quarry-update'),
    path('quarry/<int:pk>/delete/', views.QuarryDelete.as_view(), name='quarry-delete'),
    path('search/', views.search, name='search'),
    path('test/', views.TestView.as_view(), name='test'),
    path('needdirt/', views.NeeddirtView.as_view(), name='needdirt'),
    path('havedirt/', views.HavedirtView.as_view(), name='havedirt'),
    path('about/', views.AboutView.as_view(), name='about'),
]

非常感谢您的帮助。

问题很可能是由于您的相对路径造成的。尝试:

<img src="/static/media/Dirt logo3.png"... />

请注意相对于根的前导斜杠

我不喜欢文件名中的空格,所以我也会更改它

from django.urls import path
from . import views
from django.conf import settings
from django.conf.urls.static import static


app_name = 'maps'

urlpatterns = [
    # /maps/
    path('', views.IndexView.as_view(), name='index'),
    # /maps/71/
    path('<int:pk>/', views.DetailView.as_view(), name='detail'),
    path('register/', views.UserFormView.as_view(), name='register'),
    path('login/', views.LoginView.as_view(), name='login'),
    path('logout/', views.LogoutView.as_view(), name='logout'),
    # /maps/companies/
    path('companies/', views.CompView.as_view(), name='comp'),
    # /maps/equipment/
    path('equipment/', views.EquipView.as_view(), name='equip'),
    #maps/
    path('equipment/<int:pk>/', views.EquipdetView.as_view(), name='equipdet'),
    path('location/add/', views.LocationCreate.as_view(), name='location-add'),
    path('location/<int:pk>/', views.LocationCreate.as_view(), name='location-update'),
    path('location/<int:pk>/delete/', views.LocationDelete.as_view(), name='location-delete'),
    path('equipment/add/', views.EquipCreate.as_view(), name='equipment-add'),
    path('equipment/<int:pk>/', views.EquipCreate.as_view(), name='equipment-update'),
    path('equipment/<int:pk>/delete/', views.EquipDelete.as_view(), name='equipment-delete'),
    path('quarry/', views.QuarryView.as_view(), name='quarry'),
    path('quarry/<int:pk>/', views.QuarrydetView.as_view(), name='quarrydet'),
    path('quarry/add/', views.QuarryCreate.as_view(), name='quarry-add'),
    path('quarry/<int:pk>/', views.QuarryCreate.as_view(), name='quarry-update'),
    path('quarry/<int:pk>/delete/', views.QuarryDelete.as_view(), name='quarry-delete'),
    path('search/', views.search, name='search'),
    path('test/', views.TestView.as_view(), name='test'),
    path('needdirt/', views.NeeddirtView.as_view(), name='needdirt'),
    path('havedirt/', views.HavedirtView.as_view(), name='havedirt'),
    path('about/', views.AboutView.as_view(), name='about'),
]
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static



urlpatterns = [
    path('', include('maps.urls')),
    path('admin/', admin.site.urls),
    path('maps/', include('maps.urls')),
]


urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)


<img src="/static/media/Dirt logo3.png"... />