inside of the views.py
def book_detail(request, pk):
book = get_object_or_404(Library, pk=pk)
return render(request, 'book_detail.html', context={'book': book})
def admin_book_detail(request, pk):
book = get_object_or_404(Library, pk=pk)
return render(request, 'admin_book_detail.html', context={'book': book})
Hello, I am new to Django. I have two views like this. One of them is for normal user and the other one is for admin. But the template of admin takes it's information from the other one. Like, If I change the book_detail, admin_book_detail changes too. But if i change admin_book_detail's information, nothing happens.
inside of admin_book_detail.html
{% block content %}
{{ block.super }}
<div style="margin:0 auto;width:1200px;">
<h1 class="page-header" style="color:black;">{{ book.title }}</h1>
<h2> This book is <b>{{ book.availability }}</b> to borrow</h2>
<br>
<h3>Author of the Book = <b>{{ book.author }}</b></h3>
<br>
<h3>Publish Year = <b>{{ book.year }}</b></h3>
<br>
<h3> Category = <b>{{ book.category }}</b></h3>
<div style="padding: 10px 5px;">
<div style="background-color: white;padding: 10px 30px; width:175px;border: 3px solid black;text-align:center;">
<a style="color:black; font-size:19px;" href="{% url 'adminbook' %}"><b>Go Back</b></a>
</div>
</div>
</div>
{% endblock %}
inside of book_detail.html
{% block content %}
{{ block.super }}
<div style="margin:0 auto;width:1200px;">
<h1 class="page-header" style="color:black;">{{ book.title }}</h1>
<h2> This book is <b>{{ book.availability }}</b> to borrow</h2>
<br>
<h3>Author of the Book = <b>{{ book.author }}</b></h3>
<br>
<h3>Publish Year = <b>{{ book.year }}</b></h3>
<br>
<h3> Category = <b>{{ book.category }}</b></h3>
<div style="padding: 10px 5px;">
<div style="background-color: white;padding: 10px 30px; width:175px;border: 3px solid black;text-align:center;">
<a style="color:black; font-size:19px;" href="{% url 'book' %}"><b>Go Back</b></a>
</div>
</div>
{% endblock %}
inside of the url
urlpatterns = [
path('request_book/', request_book, name='request_book'),
re_path(r'book_detail/(?P<pk>[0-9]+)/', book_detail, name='book_detail'),
re_path(r'admin_book_detail/(?P<pk>[0-9]+)/', admin_book_detail, name='admin_book_detail'),
path('add_book/', add_book, name='add_book')
]
Edit : Ok I fixed it.
question from:
https://stackoverflow.com/questions/65902465/django-template-takes-the-information-from-the-other-one 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…