Nav apraksta

views.py 673B

123456789101112131415161718192021
  1. from django.shortcuts import render
  2. from .models import Topic
  3. def index(request):
  4. """The home page for Learning Log."""
  5. return render(request, 'learning_logs/index.html')
  6. def topics(request):
  7. """Show all topics."""
  8. topics = Topic.objects.order_by('date_added')
  9. context = {'topics': topics}
  10. return render(request, 'learning_logs/topics.html', context)
  11. def topic(request, topic_id):
  12. """Show a single topic, and all its entries."""
  13. topic = Topic.objects.get(id=topic_id)
  14. entries = topic.entry_set.order_by('-date_added')
  15. context = {'topic': topic, 'entries': entries}
  16. return render(request, 'learning_logs/topic.html', context)