Steps to upload images
- First go to settings and add this under static_url
MEDIA_URL = 'media/' # MEDIA_URL tells Django where to look for uploaded files when in development mode (DEBUG = True)
MEDIA_ROOT = BASE_DIR / 'media' # MEDIA_ROOT tells Django where to store uploaded files when in development mode (DEBUG = True)
- In your root project url, add these lines
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
from core.views import frontpage, about
urlpatterns = [
path('about/', about , name="about"),
path('admin/', admin.site.urls),
path('', include('store.urls')),
path('',frontpage,name="frontpage"),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Now, if you want to access the image url, do this
<img src="{{ product.image.url }} alt="image"
Top comments (0)