On Wed, Nov 30, 2022 at 09:16:39AM -0800, Michael Starr wrote:
> Thank you. Though, that hard codes everything, which is bad. How do I
> generalize it?
You'll need to do 2 things:
1. Add the pet(s) you want to the template context, probably by implementing get_context_data[1].
2. Change your template to use the pet from the template context instead of the hard code pet, Mocha. Assuming your pet in the template context is named 'pet':
<a href="{% url 'pet_details' slug=pet.slug %}">Pet Profile: {{ pet.name }}</a>
...alternatively since you've implemented get_absolute_url:
<a href="{{ pet.get_absolute_url }}">Pet Profile: {{ pet.name }}</a>
[1] https://docs.djangoproject.com/en/4.1/ref/class-based-views/mixins-simple/#django.views.generic.base.ContextMixin.get_context_data
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20221201004300.GE8954%40fattuba.com.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment