首页 \ 问答 \ 干草堆与飞快移动 - 搜索结果不重定向(Haystack with Whoosh- Search Results Not Redirecting)

干草堆与飞快移动 - 搜索结果不重定向(Haystack with Whoosh- Search Results Not Redirecting)

我成功安装了whoosh并使其与Haystack一起工作。 事情进展顺利,但我面临的一个问题是: 在搜索关键字并打印出结果后,当我点击结果(标题)时,它不会将我重定向到我点击的关键字页面,它只是静态的。 我尝试添加get_absolute_url方法。 但它不起作用。 我错过了什么?

楷模

      class Meek(models.Model):
         user=models.ForeignKey(User)
         title=models.CharField(max_length=250, unique=True)
         address=models.CharField(max_length=200)
         city=models.CharField(max_length=200)
         state=models.CharField(max_length=200)
         main_view=models.ImageField(upload_to="photos",blank=True, null=True)
         side_view=models.ImageField(upload_to="photos",blank=True, null=True)
         pub_date=models.DateTimeField()

         def __unicode__(self):
             return self.title


         @models.permalink
         def get_absolute_url(self):
             return ('findme', (), {
                'main_view': self.main_view,
                'side_view': self.side_view,
                'address': self.address,
                'city': self.city,
                'state': self.state})

搜索/ search.html

               {% block content %}

                 <h2>Search</h2>


               <form method="get" action=".">

                <table>
                  {{ form.as_table }}
                <tr><td>&nbsp;</td>
                <td>
                 <input type="submit" value="Search">
                </td>
                </tr>
                 </table>
               {% if query %}
                 <h3>Results</h3>
              {% for result in page.object_list %}
               <p>
                <a href= "{{ result.object.get_absolute_url }}" >{{ result.object.title }}</a> 
               </p>
                 {% empty %}
                    <p>No results found.</p>
                 {% endfor %}

               {% if page.has_previous or page.has_next %}
                     <div>
                       {% if page.has_previous %}<a href="?q={{ query }}&amp;page= {{ page.previous_page_number }}">{% endif %}&laquo; Previous{% if page.has_previous %}</a>
               {% endif%}

               {% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}</div>
               {% endif %}

                 {% else %}

                    {# Show some example queries to run, maybe query syntax, something else? #}

                {% endif %}
                 </form>

               {% endblock %}

URL配置

          #url where the objects are posted.
          (r'^find/$', findme), 

         #haystack url where you can search
         (r'^search/', include('haystack.urls')),

浏览次数:

           def findme(request):
               extra_data_context={}
                   #if there's nothing in the field do nothing.
               if request.method=="POST":
                  form=MeekForm(request.POST, request.FILES)
                  if form.is_valid():
                     data=form.cleaned_data
                     newmeeks=Meek(
                         user=request.user,
                         pub_date=datetime.datetime.now(),
                         title=data['title'],
                         main_view=request.FILES['main_view'],
                         side_view=request.FILES['side_view'],
                         address=data['address'],
                         city=data['city'],
                         state=data['state'])
                    newmeeks.save()
                extra_data_context.update({'MeekForm':form})
             else:
                 form = MeekForm()
                 extra_data_context.update({'MeekForm':form})
             extra_data_context.update({'Meeks':Meek.objects.filter(user=request.user)})
             return render_to_response('postme.html',extra_data_context,context_instance=RequestContext(request))

I successfully installed whoosh and made it work with Haystack. Things are working fine but I'm facing one problem which is; after searching for a keyword and it print out the results, when I click on the result(title), It won't redirect me to the page of the keyword I clicked on, it's just static. I tried adding a get_absolute_url method. Yet it's not working. What I'm I missing?

Models

      class Meek(models.Model):
         user=models.ForeignKey(User)
         title=models.CharField(max_length=250, unique=True)
         address=models.CharField(max_length=200)
         city=models.CharField(max_length=200)
         state=models.CharField(max_length=200)
         main_view=models.ImageField(upload_to="photos",blank=True, null=True)
         side_view=models.ImageField(upload_to="photos",blank=True, null=True)
         pub_date=models.DateTimeField()

         def __unicode__(self):
             return self.title


         @models.permalink
         def get_absolute_url(self):
             return ('findme', (), {
                'main_view': self.main_view,
                'side_view': self.side_view,
                'address': self.address,
                'city': self.city,
                'state': self.state})

Search/search.html

               {% block content %}

                 <h2>Search</h2>


               <form method="get" action=".">

                <table>
                  {{ form.as_table }}
                <tr><td>&nbsp;</td>
                <td>
                 <input type="submit" value="Search">
                </td>
                </tr>
                 </table>
               {% if query %}
                 <h3>Results</h3>
              {% for result in page.object_list %}
               <p>
                <a href= "{{ result.object.get_absolute_url }}" >{{ result.object.title }}</a> 
               </p>
                 {% empty %}
                    <p>No results found.</p>
                 {% endfor %}

               {% if page.has_previous or page.has_next %}
                     <div>
                       {% if page.has_previous %}<a href="?q={{ query }}&amp;page= {{ page.previous_page_number }}">{% endif %}&laquo; Previous{% if page.has_previous %}</a>
               {% endif%}

               {% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}</div>
               {% endif %}

                 {% else %}

                    {# Show some example queries to run, maybe query syntax, something else? #}

                {% endif %}
                 </form>

               {% endblock %}

Urlconf

          #url where the objects are posted.
          (r'^find/$', findme), 

         #haystack url where you can search
         (r'^search/', include('haystack.urls')),

Views:

           def findme(request):
               extra_data_context={}
                   #if there's nothing in the field do nothing.
               if request.method=="POST":
                  form=MeekForm(request.POST, request.FILES)
                  if form.is_valid():
                     data=form.cleaned_data
                     newmeeks=Meek(
                         user=request.user,
                         pub_date=datetime.datetime.now(),
                         title=data['title'],
                         main_view=request.FILES['main_view'],
                         side_view=request.FILES['side_view'],
                         address=data['address'],
                         city=data['city'],
                         state=data['state'])
                    newmeeks.save()
                extra_data_context.update({'MeekForm':form})
             else:
                 form = MeekForm()
                 extra_data_context.update({'MeekForm':form})
             extra_data_context.update({'Meeks':Meek.objects.filter(user=request.user)})
             return render_to_response('postme.html',extra_data_context,context_instance=RequestContext(request))

原文:https://stackoverflow.com/questions/11176625
更新时间:2021-12-07 11:12

最满意答案

因为JSON.parse返回Object。 res.end无法写入对象。

https://github.com/joyent/node/issues/1241


Because JSON.parse return the Object. res.end can't write object.

https://github.com/joyent/node/issues/1241

相关问答

更多
  • 您的JSON格式不正确: var text = '[{"a":"w","b","x"},{"a":"y","b":"z"}]'; ^-- This should be a ':' 它应该是: var text = '[{"a":"w","b":"x"},{"a":"y","b":"z"}]'; Your JSON is not formatted correctly: var text = '[{"a":"w","b","x"},{"a":"y","b" ...
  • app.all('/push', function(req, res) { console.log(req.body.name); // Lorem console.log(req.body.name); // 18 res.status(200).json({data:req.body); // will give { name: 'Lorem',age:18'} in response }); 您的数据将在req.body中提供 希望能帮助到你 ...
  • 你可以简单地使用JSON.parse 。 node.js构建在V8上 ,它提供了全局对象JSON [docs] 。 JSON对象的定义是ECMAScript 5规范的一部分 。 注意 - JSON.parse可以绑定当前线程,因为它是一个同步方法。 所以如果你打算解析大的JSON对象,使用一个流json解析器。 You can simply use JSON.parse. The definition of the JSON object is part of the ECMAScript 5 specif ...
  • 您不会将JSON传递给该函数(JSON将是一个字符串,因此以引号结尾/开头)。 你传递的是一个JavaScript对象文字。 看到不同: 对象文字 {"ID":"2","NAME":"John Smith","EMAIL":"johnsmith@domain.com"} JSON字符串 "{\"ID\":\"2\",\"NAME\":\"John Smith\",\"EMAIL\":\"johnsmith@domain.com\"}\" // or, easier than escaping all th ...
  • 有了这个输入json通知,你需要得到这样的: var arr = JSON.parse('[' + event.params.querystring.numbers + ']'); 而不是: var arr = JSON.parse('[' + event.numbers + ']'); 或者使身体映射模板保持您想要的方式: { "number": "$input.params('number')" } http://docs.aws.amazon.com/apigateway/latest/deve ...
  • 你应该检查回调,它们在这样的情况下非常有用。 这是您的示例的修复程序,但您应该更多地查看它们,它们肯定会帮助您成长为JavaScript开发人员。 var Parent_Object = function() { parent = this; this.element_data; this.initElementData = function() { var request = new XMLHttpRequest(); request.o ...
  • 发现这是Node v6.0.0中的一个错误,其中填充数组表示为空数组。 在git上发布此问题 。 它已在版本6.2.0上得到解决。 Found out this was a bug in Node v6.0.0 where a filled array was represented as an empty array. Posted this issue on git. It has been resolved on version 6.2.0 though.
  • 如果方法调用失败,通常有助于查看函数的输入是什么。 我建议在JSON.parse()调用之前执行console.log(localStorage.getItem("temporaryArray"))以查看问题所在。 我猜这个问题的根源是,在某些时候你正在调用localStorage.setItem("temporaryArray",value)并且忘记对localStorage.setItem("temporaryArray",value)进行JSON.stringify()。 If a method in ...
  • 因为JSON.parse返回Object。 res.end无法写入对象。 https://github.com/joyent/node/issues/1241 Because JSON.parse return the Object. res.end can't write object. https://github.com/joyent/node/issues/1241
  • response.body是原始文本响应。 只要您指定了正确的content-type标头, response.getBody()应该已经返回已解析的JSON响应。 将JS对象发送到JSON.parse导致SyntaxError 。 response.body is the raw text response. response.getBody() should already return a parsed JSON response as long as you have the correct con ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)