22 lines
657 B
Python
22 lines
657 B
Python
|
|
from django.shortcuts import render
|
||
|
|
|
||
|
|
# Create your views here.
|
||
|
|
from django.http import HttpResponse, Http404
|
||
|
|
from django.template import loader
|
||
|
|
|
||
|
|
from .models import Plant
|
||
|
|
|
||
|
|
def index(request):
|
||
|
|
latest_plants_list = Plant.objects.order_by("-create_date")[:5]
|
||
|
|
context = { "latest_plants_list": latest_plants_list }
|
||
|
|
return render( request, "planterteque/index.html", context )
|
||
|
|
|
||
|
|
def reference(request, plant_id):
|
||
|
|
try:
|
||
|
|
plant = Plant.objects.get( pk=plant_id )
|
||
|
|
except Plant.DoesNotExist:
|
||
|
|
raise Http404("Plant does not exist")
|
||
|
|
context = { "plant": plant }
|
||
|
|
return render( request, "planterteque/reference.html", context )
|
||
|
|
|