BoxTitoli_Mysql/titoli/views.py

29 lines
843 B
Python
Raw Permalink Normal View History

2020-05-22 12:05:33 +00:00
from django.shortcuts import render,get_object_or_404,redirect
from .models import Titolo
from .forms import FormTitolo
from django.http import HttpResponse
# Create your views here.
def homepage(request):
titoli = Titolo.objects.all().order_by("-unico")
context = {"titoli":titoli}
return render(request,"Homepage.html",context)
def guarda_streaming(request,id):
streaming = get_object_or_404(Titolo,id=id)
context = {"streaming":streaming}
return render(request,"streaming.html",context)
def CreateTitolo(request):
if request.method == "POST":
form = FormTitolo(request.POST)
if form.is_valid():
new_title = form.save()
return redirect("Homepage")
else:
form = FormTitolo()
context = {"form":form}
return render(request,"crea_titolo.html",context)