Thursday, December 15, 2022

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

Sorry for that crass, asinine comment. I had a flare up of my condition.
Thank you all for the help.
Mike

On Sunday, December 11, 2022 at 4:32:04 PM UTC-8 Michael Starr wrote:
It's poorly written and mine isn't. Am I better than them.

On Monday, December 5, 2022 at 6:36:30 AM UTC-8 elvisa...@gmail.com wrote:
Good !😁

Le dim. 4 déc. 2022 à 22:04, Michael Starr <mi...@spinningcow.xyz> a écrit :
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: {{ 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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e8afb697-d067-4cc6-bda8-93dd9b8748een%40googlegroups.com.

--
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/43d43c8a-6393-4398-8040-7431a915844bn%40googlegroups.com.

No comments:

Post a Comment