Hello, I want to two slugs in one URL pattern. These slugs from different models. I have a model Link with a many to one relationship with a model category.
Actually these two slugs is working. But one of the slugs is accepting whatever I write in the category_slug section of the url. Let's say: I write 127.0.0.1:8000/there_is_no_name_like_that_in_the_database/pk/slug this. I am going to this page but there is no category with this name. So, basically is accepting whatever I write. *#links/views.py* class LinkDetailView(FormMixin, DetailView): model = Link context_object_name = 'link' form_class = CommentForm success_url = reverse_lazy('home') def get_object(self, queryset=None): return get_object_or_404(Link, pk=self.kwargs['pk'], slug=self. kwargs['slug']) ... *#links/urls.py* urlpatterns = [ ... url( regex=r '^k/(?P<category>[\w-]+)/(?P<pk>\d+)(?:/(?P<slug>[\w\d-]+))?/$', view=views.LinkDetailView.as_view(), name='link_detail' ), ... ] -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0b8482ee-5e64-4ee8-a664-d1d938767bd6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.