简体   繁体   English

如何在 Django 中将查询集从一个视图传递到另一个视图

[英]How to pass queryset from one view to another in Django

I have searched for this but none of the solutions seem to work especially sessions.我已经搜索过这个,但似乎没有一个解决方案特别适用于会话。 I have a queryset and i have appended it to a list of tuples such that it looks like this: [(a,b,c),(d,e,f), ...]我有一个查询集,我已将其附加到元组列表中,如下所示: [(a,b,c),(d,e,f), ...]

I want to pass that to another view.我想把它传递给另一个视图。 How do I achieve this?我如何实现这一目标?

Here is a code snippet:这是一个代码片段:

views.py视图.py

  def  view1(request):
     job_details.append((job, recruiter, salary))


  def view2(request):
     #I want to access the queryset(job_details) here

I'm not sure exactly what your trying to do, but you could POST the data to your view either via a HTML form or via JavaScript using AJAX.我不确定您到底想做什么,但您可以通过 HTML 表单或使用 AJAX 的POST将数据发布到您的视图。 Here is generally a good start to do it with JavaScript.使用JavaScript通常是一个好的开始。

If you look at the source code of Django-filter you will find that it encodes a user-specified queryset as the GET part of the URL.如果您查看Django-filter的源代码,您会发现它将用户指定的查询集编码为 URL 的 GET 部分。

Or, it's possible that you just want to use Django-filter.或者,您可能只想使用 Django-filter。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM