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 7417519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:43:04+00:00 2026-05-29T07:43:04+00:00

I am trying to use django-haystack (been around 2 days now), and I have

  • 0

I am trying to use django-haystack (been around 2 days now), and I have got the basic Getting Started example working and it looks very impressive. I would now like to try the autocomplete function on haystack.

http://readthedocs.org/docs/django-haystack/en/v1.2.4/autocomplete.html

The first part seems fine: “Setting up the data” seems simple enough. However, I am not sure where the “Performing the Query” needs to be written: i.e in which view should I include:

from haystack.query import SearchQuerySet
sqs = SearchQuerySet().filter(content_auto=request.GET.get('q', ''))

My current urls.py is simple and set up as follows:

urlpatterns = patterns('',
    # Examples:
    ('^hello/$', hello),
    (r'^$', hello), 
    (r'^search/', include('haystack.urls')),
    # url(r'^$', 'mysite.views.home', name='home'),
    # url(r'^mysite/', include('mysite.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    #url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)

Looking at the following blog:

http://tech.agilitynerd.com/haystack-search-result-ordering-and-pre-rende

I would like to have something like:

url(r'^search/', SearchView(load_all=False,searchqueryset=sqs),name='haystack_search'), 

but, where should the sqs be specified? in the urls.py or views.py? I tried both, but they give me a name error “request” not found on the sqs statement.

  • 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-05-29T07:43:05+00:00Added an answer on May 29, 2026 at 7:43 am

    Usually this would be in your own haystack urls, haystack.urls in your current urls.py is pointing to the default urls. Create a file haystack_urls.py and in your urls.py add it e.g.

    url(r'^search/', include('yourproject.haystack_urls')),
    

    in that file you can then add your custom code e.g.

    from haystack.views import SearchView
    from haystack.query import SearchQuerySet
    
    sqs = SearchQuerySet() # edit remove line that was incorret
    
    urlpatterns = patterns('haystack.views',
        url(r'^&', SearchView(load_all=False,searchqueryset=sqs),name='haystack_search'), 
    )
    

    to wrap a view for request try something like

    class SearchWithRequest(SearchView):
    
        __name__ = 'SearchWithRequest'
    
        def build_form(self, form_kwargs=None):
            if form_kwargs is None:
                form_kwargs = {}
    
            if self.searchqueryset is None:
                sqs = SearchQuerySet().filter(content_auto=self.request.GET.get('q', ''))
                form_kwargs['searchqueryset'] = sqs
    
            return super(SearchWithRequest, self).build_form(form_kwargs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small app I'm working on where I'm trying to use Django's
I'm working on getting django-haystack set up on my site, and am trying to
Iam new to django-haystack, and I am trying to follow the getting started guide.
I have been trying to use django-allauth to provide Social registration, but I am
I'm trying to use iexact in my Django app. I have items in my
I am getting cannot import name connections exception while trying to use django-multilingual-ng 0.1.20
I've been trying to use Django-appengine to write a small web app, but I
I'm trying to use django-evolution to modify some models from an existing project. Now
I'm trying to use django-taggit ( see ). This is what I have in
I'm trying to use MySQL with django and right now the following isn't executing

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.