On Jan 5, 5:24 am, Delacroy Systems <webad...@delacroy.co.za> wrote: > I want to allow a user to search for a value and return the results > using the object_list generic view. How can I get this working? > > business_search.html: > {% block content %} > <form action="" method="get"> > Business name:<input type="text" name="business" /> > <input type="submit" value="Search" /> > {% endblock content %} > > urls.py: > (r'^?business=(?P<business_name>\w+)/','businessnamesearch_view'), > > views.py: (field in models.py to search on is named business) > def businessnamesearch_view(request, business_name): > business = Business.objects.filter > (business__icontains=business_name) > return object_list(request, queryset=business) > > I have a template, business_list.html that works already. > > I get the error: > Request Method: GET > Request URL: http://127.0.0.1:8000/business/?business=AB > Exception Type: error > Exception Value: nothing to repeat
"Nothing to repeat" is a regex error - the initial question mark is not escaped, so Python thinks you are trying to use it as a wildcard. In fact, you are going about this the wrong way. Query parameters - those after the ? in a URL - are not dealt with in the URLconf at all, but are passed in the request.GET dictionary. So you your urlconf should be: (r'^$', 'businessnamesearch_view') and the view should be: def businessnamesearch_view(request): business_name = request.GET.get('business') ...etc... -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.