- We first create app’s own urls.py and put all the paths related to the app,, see [[Define app URLs under their own path]].
- In app’s urls.py, define a path pattern which matches the object’s detail page:
from django.urls import path
from . import views
urlpatterns = [
path('<int:movie_id>/', views.detail, name='detail')
]
- Define a detail view:
from django.shortcuts import render, get_object_or_404
from .models import Movie
def detail(request, movie_id):
movie = get_object_or_404(Movie, pk=movie_id)
return render(request, 'detail.html', { 'movie': movie })
- create a template file detail.html
{% extends 'base.html' %}
{% block content %}
<div>
<div>{{ movie.title }}</div>
<div>{{ movie.description }}</div>
</div>
{% endblock content %}