1 from django.shortcuts import render
2 from django.http import HttpResponse
3 from django.template import loader
5 from random import randint
7 from .models import Author, Quote, Tag
9 # Create your views here.
10 def onequote(request, quote_id):
11 q = Quote.objects.get(id=quote_id)
12 context = { 'quote' : q }
13 return render(request, 'quotes/onequote.html', context)
16 count = Quote.objects.count()
17 return onequote(request, randint(1, count))
19 def tags(request, tag_id):
20 tag = Tag.objects.get(id=tag_id)
21 context = { 'tag' : tag }
22 return render(request, 'quotes/tag.html', context)
24 def author(request, author_id):
25 author = Author.objects.get(id=author_id)
26 context = { 'author' : author }
27 return render(request, 'quotes/author.html', context)
30 quotes = Quote.objects.all()
31 context = { 'quotes' : quotes }
32 return render(request, 'quotes/all.html', context)