Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- url.py
- from django.urls import path, re_path
- from . import views
- urlpatterns = [
- path('', views.list, name='list'),
- re_path(r'^[A-Z]{1}/', views.list_detail, name='list_detail')
- ]
- views.py
- from django.shortcuts import render
- import string
- from home.models import Anime
- alphabet = string.ascii_uppercase
- def list(request):
- context = {'alphabet': alphabet}
- return render(request, 'list/list.html', context)
- def list_detail(request):
- anime = Anime.objects.order_by('title')
- context = {'anime': anime}
- return render(request, 'list/detail.html', context)
- list.html
- {% extends 'base/base.html' %}
- {% load static %}
- {% block head %}
- <link rel="stylesheet" type="text/css" href="{% static 'list/style.css' %}">
- {% endblock %}
- {% block content %}
- <div class="panel-body anime-list text-center">
- <div class="btn-group btn-group-xs">
- {% for i in alphabet %}
- <a href="{{i}}" class="btn">{{i}}</a>
- {%endfor%}
- </div>
- </div>
- {% endblock %}
- detail.html
- {% extends 'list/list.html' %}
- {% block content %}
- {% for a in anime %}
- <p>{{ a.title }}</p>
- {% endfor %}
- {% endblock %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement