python - 通过view1呈现的HTML将参数从视图函数传递到另一个而不更改URL?
问题描述
我在 django 中有 2 个视图函数:
def view1(request):
dict_ex = Mod.objects.all()
............... (modifying and processing the dict_ex variable)
return render(request, 'view1.html', {"dd": dict_ex})
然后我在 view1.html 中有这些行:
{% for k, v in dd.items %}
Name: {{ v }}
<a class="btn btn-primary" href="{% url 'view2' k.id %}">Choose this </a>
{% endfor %}
然后我的 view2 需要修改后的 dict_ex 来获取所需的其他值:
def view2(request):
dict_ex = Mod.objects.all()
............... (modifying and processing the dict_ex variable)
....... (obtaining var1 from different operations on dict_ex)
return render(request, 'view2.html', {"v": var1})
有什么方法可以通过 view1.html 将修改后的 dict_ex 从 view1 传递到 view2 函数?
我也不想在 view2 中重复这些代码行
dict_ex = Mod.objects.all()
............... (modifying and processing the dict_ex variable)
有没有办法像这样访问 view2 函数:
view2(request, dict_ex)
不改变网址?
我的 URL_PATTERNS 中有这些:
path('view_one/', view1, name='view1'),
path('view_two/<int:id>', view2, name='view2'),
解决方案
推荐阅读
- laravel - VueJs Props not read when setting initial value in data
- php - 解密后无法读取变量和其他函数
- c - Test Cases Failure on Hackerrank
- java - 我们可以访问哪些其他位置,例如 Java 中的“user.dir”?
- eclipse - 问题:无法创建任务或键入 projectImport
- hibernate - Session not getting created after upgrading to hibernate 5
- java - How to stop printing log4j FileNotFound Error on console?
- javascript - 如何修复复选框错误?
- sql-server - 超时已过。在操作完成之前超时时间已过或服务器在 VB.Net 中没有响应
- python - 有没有办法在 Python3 中使用 enumerate 进行 for 循环后递增?