I am wondering how to do so that after creating a new object, a page with the details of the given object is automatically created. Of course, the page according to the template. I have a list of objects owned by the user and a "details" button next to each object. I would like this button to take you to the details page of this object.
CodePudding user response:
Use DetailView
for that case.
views.py:
from django.views.generic import DetailView
from your_app.models import YourObject
class YourObjectDetailView(DetailView):
model = YourObject
...
ulrs.py:
ulrpatterns = [
...
path('your_app/<int:pk>/', YourObjectDetailView.as_view(), name='your-object-detail'),
...
] # pk is the id of the object if you didn't change primary key
To get url specified to the object in template:
{% url 'your-object-detail' some_id %}