0

I have a Django project where I'm trying to create a card with an image that was uploaded by the user. I keep getting a certain error but I have already done every solution and its still coming up. any help would be appreciated. the {{image}} variable isn't working

html page

<div class="p-5 mx-4 bg-white border-2 border-gray-300 grow">
    <button><img src="{{image}}" alt=""></button>
    <h3>{{title}}</h3>
    <span>{{currentBid}}</span>
    <span>{{sellor}}</span>
    </div>

settings

MEDIA_URL ='/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')\

urls

urlpatterns = [
path("", views.activeListings, name="activeListings"),
path("login", views.login_view, name="login"),
path("logout", views.logout_view, name="logout"),
path("register", views.register, name="register"),
path("createListing", views.createListing, name="createListing"),
path("listingPage/<str:title>", views.listingPage, name="listingPage"),
path("wishlist", views.wishlist, name="wishlist"),
path("catagory", views.catagory, name="catagory"),
path("catagoryListing/<str:catagory>", views.catagoryListingsPage, name='catagoryActiveListingsPage'),
path("catagoryListing/listingPage/<str:title>", views.listingPage, name="catagorylistingPage"),
] 

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

I also have the media url pattern line in the urls for my whole project

error

04 4334
Not Found: /Screen_Shot_2022-10-10_at_5.42.19_PM.png
WARNING:django.request:Not Found: /Screen_Shot_2022-09-19_at_2.39.14_PM.png
Not Found: /images/Screen_Shot_2022-10-21_at_7.37.57_AM.png
Not Found: /images/Screen_Shot_2022-09-20_at_3.08.27_PM.png
WARNING:django.request:Not Found: /Screen_Shot_2022-10-10_at_5.42.19_PM.png
[26/Oct/2022 12:01:48] "GET /images/Screen_Shot_2022-09-19_at_2.38.33_PM.png HTTP/1.1" 404 4355
WARNING:django.request:Not Found: /images/Screen_Shot_2022-10-21_at_7.37.57_AM.png
Not Found: /temperature-anomaly_wlbvLbQ.png
WARNING:django.request:Not Found: /images/Screen_Shot_2022-09-20_at_3.08.27_PM.png
[26/Oct/2022 12:01:48] "GET /Screen_Shot_2022-09-19_at_2.39.14_PM.png HTTP/1.1" 404 4334
WARNING:django.request:Not Found: /temperature-anomaly_wlbvLbQ.png
[26/Oct/2022 12:01:48] "GET /Screen_Shot_2022-10-10_at_5.42.19_PM.png HTTP/1.1" 404 4334
[26/Oct/2022 12:01:48] "GET /images/Screen_Shot_2022-10-21_at_7.37.57_AM.png   HTTP/1.1" 404 4355
[26/Oct/2022 12:01:48] "GET /images/Screen_Shot_2022-09-20_at_3.08.27_PM.png  HTTP/1.1" 404 4355
[26/Oct/2022 12:01:48] "GET /temperature-anomaly_wlbvLbQ.png HTTP/1.1" 404 4307

debug is set to true

Dunham
  • 101
  • 3

1 Answers1

0

when you use {{image}} it will get this /temperature-anomaly_wlbvLbQ.png

so I think you should add url before image

in react I used in this way:

imgApi + obj.startup_logo

where imgApi is url, for example : http://127.0.0.1 and obj.startup_logo is image path, example: /temperature-anomaly_wlbvLbQ.png

Hashem
  • 595
  • 1
  • 3
  • 8