Sunday, December 4, 2022

Re: URL evaluates to 'slug' literally instead of the variable slug

Thank you, Peter. I forgot to acknowledge your contribution.

On Wednesday, November 30, 2022 at 4:43:47 PM UTC-8 Ryan Nowakowski wrote:
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: {{ }}</a>

...alternatively since you've implemented get_absolute_url:

<a href="{{ pet.get_absolute_url }}">Pet Profile: {{ }}</a>


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
To view this discussion on the web visit

No comments:

Post a Comment