首页 > 解决方案 > 附加查询字符串以查看渲染函数 Django

问题描述

querystring认为:

def my_view(request):
    query_string  = request.GET

然后我在这个视图中做了一些工作人员。最后,我想querystring在页面完全呈现时附加到视图的 URL:

return render(request, 'my_template.html', context=context) # Want to add querystring here!

简而言之,我想附加querystring到视图渲染功能或类似的东西。我怎样才能做到这一点?


渲染过程:

我想我必须宣布我的目的。我将解释所有渲染过程并定义我的意思。看:

  1. 用户点击进入该视图的链接(发送请求)。假设这是我们的链接:

    site.com/my/page/?q1=value_1&q2=value_2
    
  2. 查看函数调用:

    # urls.py
    path('my/page/', my_view)
    
    # views.py
    def my_view(request):
        query_string  = request.GET 
    
  3. request使用,template和渲染模板context

    return render(request, 'my_template.html', context=context)
    
  4. 完成 html 和所有静态文件后,我们就有了 html 页面,其中包含URLhtml.

我想将我的主节点添加querystring到进程 4 的 URL。我该怎么做?

标签: pythondjangodjango-views

解决方案


推荐阅读