diff --git a/common/settings.py b/common/settings.py index 8d5514d..eab0012 100644 --- a/common/settings.py +++ b/common/settings.py @@ -17,6 +17,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'easy_thumbnails', 'recette', ] @@ -75,4 +76,10 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'static') MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') +THUMBNAIL_ALIASES = { + '': { + 'thumbnail': {'size': (120, 120), 'crop': True}, + }, +} + from .local_settings import * diff --git a/common/urls.py b/common/urls.py index 2eb1e03..ee44897 100644 --- a/common/urls.py +++ b/common/urls.py @@ -1,5 +1,7 @@ +from django.conf import settings from django.contrib import admin from django.urls import path +from django.views.static import serve from recette.views import home, recette @@ -9,3 +11,10 @@ urlpatterns = [ path('', home, name='home'), path('recette//', recette, name='recette'), ] + +if settings.DEBUG: + urlpatterns += [ + path('media/', serve, { + 'document_root': settings.MEDIA_ROOT, + }), + ] diff --git a/requirements.txt b/requirements.txt index e5456a2..d936b21 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ django>=2.0 pillow +easy-thumbnails==2.5 diff --git a/templates/index.html b/templates/index.html index 9727e7d..983c960 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,19 +1,34 @@ {% extends 'base.html' %} +{% load thumbnail %} + +{% block extrahead %} + +{% endblock %} {% block content %}

Recettes

-
{% csrf_token %} +{% csrf_token %} {{ form.as_p }} - +
{% if num_results is not None %}
{{ num_results }} résultat(s)
{% endif %} -