Bonjour, vous allez bien ? Je cherche à mettre imagefield à la place d'URLField ,mais cela plante à chaque fois, Django version 2.1, j'ai ce problème ValueError: The 'image' attribute has no file associated with it. Merci pour votre aide. Le Code lié à l'image
sittings.py
urls
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 MEDIA_ROOT=os.path.join(BASE_DIR, "media") MEDIA_URL="/media/"
list.html
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 from django.conf import settings from django.views.static import serve from django.conf.urls.static import static from django.conf.urls import url if settings.DEBUG: urlpatterns+=[ url(r'^media/(?P<path>.*)$', serve, { 'document_root':settings.MEDIA_ROOT, }), ]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
models.py
Code html : Sélectionner tout - Visualiser dans une fenêtre à part <img class="img-responsive" src="{{ article.image.url }}">
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 class Article(models.Model): .... image=models.ImageField(upload_to="",blank=True) ...
Partager