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
[CODE]
MEDIA_ROOT=os.path.join(BASE_DIR, "media")
MEDIA_URL="/media/"[/CODE]
urls
[CODE]
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)
[/CODE]
list.html
[CODE]
<img class="img-responsive" src="{{ article.image.url }}">
[/CODE]
models.py
[CODE]
class Article(models.Model):
....
image=models.ImageField(upload_to="",blank=True)
...[/CODE]
- Edité par Anonyme 30 juillet 2019 à 14:46:35
Changer URLfield par ImageFied
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.