Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8081161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:38:54+00:00 2026-06-05T16:38:54+00:00

I’m using this JQuery autocomplete plugin http://www.devbridge.com/projects/autocomplete/jquery/ in my project. I followed this tutorial

  • 0

I’m using this JQuery autocomplete plugin http://www.devbridge.com/projects/autocomplete/jquery/ in my project. I followed this tutorial http://tips4php.net/2010/09/ajax-autocomplete-with-jquery-and-php/.

jQuery code for Autocomplete:

$('#add-keywords').autocomplete({ 
        serviceUrl:'/keywords_suggestions',
        minChars:3,
        maxHeight:220,
        width:280,
        zIndex: 9999,
        onSelect: function(value, data){ $('#add-keywords').val(value); },
});

The Ajax GET request from JQuery Autocomplete has no problem. It is like, if I type “developer” in the input text the GET request url would be

http://127.0.0.1:8000/keywords_suggestions/?query=developer

I’m getting that parameter query in Django like this:

def kkeywords_suggestions(request):
        if request.is_ajax():
                q = request.GET.get('query', '')
                try:
                        g = KeywordsModel.objects.filter(keyword__startswith=q).order_by('count')
                except KeywordsModel.DoesNotExist:
                        return HttpResponse("not")
                else:
                        for i in range(1,(len(g)+1)):
                                s = []
                                s.append(g[i-1].keyword)
                        to_json = {
                                query: q,
                                suggestions: s,
                                }
                        return HttpResponse(simplejson.dumps(to_json), mimetype='application/json')

Django Models.py:

class KeywordsModel(models.Model):
        keyword = models.CharField(max_length=40, blank=False)
        count = models.IntegerField(max_length=20)

The problem occurs from here request.GET.get('query', ''). It shows the error

ValueError at /keywords_suggestions/
The view information.views.keywords_suggestions didn't return an HttpResponse object.

UPDATE-1

Sorry, the error in Chrome Network tab is like this

Request URL:http://127.0.0.1:8000/keywords_suggestions/?query=web
Request Method:GET
Status Code:500 INTERNAL SERVER ERROR

When I checked in that URL, It shows blank page. Why?

UPDATE-2

I removed request.is_ajax() from the views. Now I’m getting this error:

Exception Type: NameError
Exception Value:    
global name 'query' is not defined
Exception Location: /home/nirmal/try/information/views.py in keywords_suggestions, line 123

Why django considering query as a global name? It is the one I’m trying to fetch from the url.

Could anyone help me to make a perfect HttpResponse for that Autocomplete feature?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:38:55+00:00Added an answer on June 5, 2026 at 4:38 pm

    it should be.

    to_json = {'query': q, 'suggestions': s}
    

    basically what was happening is that {query:q ... python was looking for the variable query in order to set the key in the dictionary, to what ever string query may have being pointing to, but no such variable existed and such it returned an error …

    global name 'query' is not defined as the error states, python was looking for variable query, it first checks locally in the function scope and then it moves upwards until it hits the global scope if it isn’t found it throws that exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.