Models2 [Python Django] The Practical Guide - Data & Models (3) Model URLs li>a href="{% url "book-detail" book.id %}">{{ book.title }} (Rating: {{ book.rating }})a> li> index.htmlurlpatterns = [ path("", views.index), path("", views.book_detail, name="book-detail")]urls.pyURL을 생성하기 위해 {% url %} 템플릿 태그 사용def get_absolute_url(self): return reverse("book-detail", args=[self.id]) models.py li>a href="{{ book.get_absolute_url }}">{{ book.title }} (Rating: {{ bo.. 2025. 7. 22. [Python Django] The Practical Guide - Data & Models (2) {% extends "book_outlet/base.html" %}{% block title %} All Books{% endblock %}{% block content %} {% for book in books %} {{ book.title }} (Rating: {{ book.rating }}) {% endfor %} {% endblock %}index.html from django.shortcuts import get_object_or_404, renderfrom django.http import Http404from .models import Book# Create your views here.def index(request): .. 2025. 7. 22. 이전 1 다음