English 中文(简体)
Django - How use general perspectives from a Django External App in my own App?
原标题:Django - How use generic views from a Django external App in my own App?

I m New to Django...

我已安装了一个称为Haystack的Django外部应用系统,该外部应用在“python2.6/site- Packages/haystack”内有“view.py”。 我认为,“观点.py”在Django语中被称为“遗传观点”。

采用“urls.py”这样的通用观点:

urlpatterns = patterns( haystack.views , 
                   url(r ^search/$ , FacetedSearchView(form_class=FacetedSearchForm, searchqueryset=sqs), name= haystack_search ), 
)

我需要从这种一般性观点跳跃到我的应用。 我的问题是,我如何能够做到这一点?

Haystack“views.py”守则就是这样:

from django.conf import settings
from django.core.paginator import Paginator, InvalidPage
from django.http import Http404
from django.shortcuts import render_to_response
from django.template import RequestContext
from haystack.forms import ModelSearchForm, FacetedSearchForm
from haystack.query import EmptySearchQuerySet


RESULTS_PER_PAGE = getattr(settings,  HAYSTACK_SEARCH_RESULTS_PER_PAGE , 20)


class SearchView(object):
    ...

    def __init__(self, template=None, load_all=True, form_class=None, searchqueryset=None, context_class=RequestContext, results_per_page=None):
    ...

    def __call__(self, request):
    ...

    def build_form(self, form_kwargs=None):
    ...

    def get_query(self):
    ...

    def get_results(self):
    ...

    def build_page(self):
    ...

    def extra_context(self):
    ...

    def create_response(self):
    ...


def search_view_factory(view_class=SearchView, *args, **kwargs):
    ...


class FacetedSearchView(SearchView):
    ...

    def __init__(self, *args, **kwargs):
    ...

    def build_form(self, form_kwargs=None):
    ...

    def extra_context(self):
    ...


def basic_search(request, template= search/search.html , load_all=True, form_class=ModelSearchForm, searchqueryset=None, context_class=RequestContext, extra_context=None, results_per_page=None):
    ...

难道有人会给我采取什么步骤,从“urls.py”中删除该守则,并把事情放在我的“观点......py”应用中?

Best Regards,

最佳回答

Try to put (r ^search/ , include( haystack.urls )),. You also might want to read "Getting started with Haystack"

Try:

#your root urls.py
from django.conf.urls.defaults import *
from haystack.forms import FacetedSearchForm
from haystack.query import SearchQuerySet
from haystack.views import FacetedSearchView

sqs = SearchQuerySet().filter(author= john )

urlpatterns = patterns( haystack.views ,
url(r ^/my_custom_very_special_url$ , FacetedSearchView(
    template= my/special/path/to/faceted_search.html ,
    searchqueryset=sqs,
    form_class=FacetedSearchForm
), name= haystack_search ),
)

BTW, s all in the docs

问题回答

http://docs.haystacksearch.org/dev/tutorial.html“rel=“nofollow”

使用extra_context 在该背景下增加或超过其他变量的方法。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签