Re: Django and jQuery Autocomplete Routing Help
On 3/9/07, johnny <[EMAIL PROTECTED]> wrote: > > I am new to python and javaScript, I have created a funtion that > return the tags via ajax. I tried to replicate the php example. But > it's not working. I doesn't return any tags back to my html page via > ajax. I need some help. I am using jQuery autocomplete plugin from > here: > http://just-tech.blogspot.com/2006/12/jquery-tweaking-auto-complete-plugin.html. > Here is my function in view: > > def tag_autocomplete(request): > #$q = $_GET['q']; > #foreach($countries as $country) { > #if(eregi("^".$q, $country)) { > #echo $country."\r\n"; > #} > > s = request.GET.get('q', '') > current_tags = list(Tag.objects.all()) > for tag in current_tags: > if (search (s.lower(), tag.normalized_tag)): > print "%s" % (tag.normalized_tag) > For django, just print won't return the result, but print output in the console(if you are using develping server), you should return a HttpResponse() object, and the good format of the returned data is json, so there is a example from your code: from django.utils import simplejson s = request.GET.get('q', '') #current_tags = list(Tag.objects.all()) result = [] for tag in Tag.objects.filter(name=s): #if (search (s.lower(), tag.normalized_tag)): #print "%s" % (tag.normalized_tag) result.append(tag.normalized_tag) return HttpResponse(simplejson.dumps(result)) If you are using Firefox and installed Firebug plugin, you can see the response message. -- I like python! UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad My Blog: http://www.donews.net/limodou --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django and jQuery Autocomplete Routing Help
I am new to python and javaScript, I have created a funtion that return the tags via ajax. I tried to replicate the php example. But it's not working. I doesn't return any tags back to my html page via ajax. I need some help. I am using jQuery autocomplete plugin from here: http://just-tech.blogspot.com/2006/12/jquery-tweaking-auto-complete-plugin.html. Here is my function in view: def tag_autocomplete(request): #$q = $_GET['q']; #foreach($countries as $country) { #if(eregi("^".$q, $country)) { #echo $country."\r\n"; #} s = request.GET.get('q', '') current_tags = list(Tag.objects.all()) for tag in current_tags: if (search (s.lower(), tag.normalized_tag)): print "%s" % (tag.normalized_tag) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django and jQuery Autocomplete Routing Help
On 3/6/07, johnny <[EMAIL PROTECTED]> wrote: > > I am using jQuery to do the autocomplete. Autocomplete request > backend script like this: script_url?q=foo. But there is a problem > with django routing? > > (r'^tag/autocomplete/?q=(?P\w+)/$', > 'apps.tag.views.tag_autocomplete'), > > Here is my error: > > [05/Mar/2007 15:11:51] "GET /tag/autocomplete/?q=a HTTP/1.1" 404 4218 > [05/Mar/2007 15:11:51] "GET /jquery/img/indicator.gif HTTP/1.1" 404 > 3697 > [05/Mar/2007 15:11:52] "GET /tag/autocomplete/?q=app HTTP/1.1" 404 > 4218 > > Thank you. > Because django will parse the string after '?' as QueryString, so your url pattern should be: (r'^tag/autocomplete/$') And process q=xxx in request.GET, for example: s = request.GET.get('q', '') >> [05/Mar/2007 15:11:51] "GET /jquery/img/indicator.gif HTTP/1.1" It seems that you didn't correctly setup the static files, if you are using development server(via manage.py runserver), you should see the document: http://www.djangoproject.com/documentation/static_files/ -- I like python! UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad My Blog: http://www.donews.net/limodou --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---