Re: Search box: Nothing to repeat error
Thank you very much, it worked. Here's the code...: def businessnamesearch_view(request): search = request.GET.get('business') business = Business.objects.filter(business__icontains=search) return render_to_response('portal/business_list.html', {'object_list' : business} ) On Jan 5, 11:15 am, Daniel Roseman wrote: > On Jan 5, 5:24 am, Delacroy Systems 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 %} > > > > Business name: > > > > {% endblock content %} > > > urls.py: > > (r'^?business=(?P\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.
Re: Search box: Nothing to repeat error
On Jan 5, 5:24 am, Delacroy Systems 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 %} > > Business name: > > {% endblock content %} > > urls.py: > (r'^?business=(?P\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.
Search box: Nothing to repeat error
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 %} Business name: {% endblock content %} urls.py: (r'^?business=(?P\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 -- 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.