The error is due to not having a slug. You’ll have to create a URL path to
/restaurants/ if you want to allow an empty slug.
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On
Behalf Of Can Hicabi Tartanoglu
Sent: Thursday, July 12, 2018 5:06 AM
To: Django users
Subject: Pass empty slug field in urls
Hello.
I am trying to make this system work:
Restaurant/views.py:
class SearchRestaurantListView(ListView):
# template_name = 'restaurants/restaurantlocation_list.html'
def get_queryset(self):
print(self.kwargs)
slug = self.kwargs.get("slug")
if slug:
print("working")
queryset = RestaurantLocation.objects.filter(
Q(category__iexact=slug) | Q(category__icontains=slug)
)
else:
queryset = RestaurantLocation.objects.all()
return queryset
urls.py:
path('restaurants//', SearchRestaurantListView.as_view())
When the slug field is empty the debugger states it couldn't find
'restaurants/', the statement above should work no? Appearently not. Please help
--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to
django-users@googlegroups.com<mailto: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/9671ccb3-51e6-41d0-b461-7def9dc2425f%40googlegroups.com<https://groups.google.com/d/msgid/django-users/9671ccb3-51e6-41d0-b461-7def9dc2425f%40googlegroups.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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/b468e38a9d534a128beabf75caeb9f47%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.