I made a site in Django and when i try to view the pages from the database i get the alt and not the image.
File Structure
Project
-.venv
-main
-static (again here, only then does it seem to show static files)
*settings.py
*urls.py
*wsgi.py
...
-app
...
*views.py
*models.py
*admin.py
*apps.py
...
-templates
...
*offers.html
...
-static
-static stuff are in here, not important
-staticfiles
-static stuff are in here, not important
-media
-offers
*VSy6kJDNq2pSXsCzb6cvYF.jpg
*db.sqlite3
*passenger_wsgi.py
*passenger_wsgi.pyc
Settings.py
MEDIA_URL= '/media/'
MEDIA_ROOT= os.path.join(BASE_DIR, 'media')
STATIC_URL = '/static/'
STATIC_ROOT=os.path.join(BASE_DIR,'staticfiles')
STATICFILES_DIRS = [
BASE_DIR / "static",
]
urls.py
urlpatterns = [
path('', homepage),
path('servises', servisespage),
path('offers', offerpage),
path('products', productspage),
path('admin/', admin.site.urls),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
# Adding MEDIA_URL and root does not work either
views.py
def offerpage(request):
ids = Offer.objects.values_list('id', flat=True)
obj_list = []
for id in ids:
obj = Offer.objects.get(id=id)
obj_list.append(obj)
context = {
"objects": obj_list
}
return render(request, "offers.html", context)
offers.html
<main>
</main>
When i try to inspect the site on firefox, in the image source i get:
src="/media/offers/VSy6kJDNq2pSXsCzb6cvYF.jpg"
(offers is the folder which i used in the upload_to parameter in the models.py)
Thanks for all and any of your help!!!
Aucun commentaire:
Enregistrer un commentaire