class AuthorDetailView(DetailView):
model = Author
template_name = 'catalog/author_detail.html'
def get_context_data(self, **kwargs):
context = super(AuthorDetailView, self).get_context_data(**kwargs)
context['author_books'] = Book.objects.filter(author=pk).values('title', 'summary')
return context
как мне pk передать в views.py используя DetailView&
urlpatterns = [
path('', views.index, name='index'),
path('books/', views.BookListView.as_view(), name='books'),
path('book/<int:pk>/', views.BookDetailView.as_view(), ),
path('authors/', views.AuthorListView.as_view(), name='authors'),
path('author/<int:pk>/', views.AuthorDetailView.as_view(), name='author-detail')
]
import xml.etree.ElementTree as ET
data = '''<?xml version="1.0" encoding="UTF-8"?><response version="1.0"><merchant><id>000000</id><signature>5d7fcffa2290b7ed4ad98ff259d6b79420f01ce5</signature></merchant><data><oper>cmt</oper><info><statements status="excellent" credit="0.0" debet="107.0">
<statement card="012345678910" appcode="00000" trandate="2020-05-15" trantime="13:14:00" amount="92.00 UAH" cardamount="-92.00 UAH" rest="4363.19 UAH" terminal="LIQPAY*Privat24 Androi, I0110UWI" description="Пополнение мобильного +380970000000"/>
<statement card="012345678910" appcode="0000" trandate="2020-05-10" trantime="00:02:00" amount="15.00 UAH" cardamount="-15.00 UAH" rest="4455.19 UAH" terminal="PrivatBank, C400" description="Перевод на карту ПриватБанка через приложение Приват24. Получатель: Іванов Іван Іванович"/>
</statements></info></data></response>'''
root = ET.fromstring(data)
statement = root.find('data/info/statements/statement')
rest = statement.get('rest')
description = statement.get('description')
statements = root.find('data/info/statements')
for statement in statements:
print(statement.get('rest'))
print(statement.get('description'))