放置request.path to django模板中的URL参数
我想创建一个向页面的后退按钮,该按钮可以从另一个页面访问链接。为此,我想将第一页的路径放在链接中,在下一页上,我可以将其放在后面的按钮上。
我有这个锚标: < a href =“ {%url'page'path = request.path%}”> to page</a>
当我尝试去网站时,我会收到以下错误:
带有关键字参数'{'path'':'/my_site/'}'的“页面”的反向。 1个模式(S)尝试:['notifications \\/(?p< path> [^/]+)\\ z']
I want to create a back button to a page which can be accessed with a link from another page. To do this, I want to put the first page's path to the link, and on the next page I can put it to the back button.
I have this anchor tag:<a href="{% url 'page' path=request.path %}">Go to page</a>
When I try to go to the site I get the following error:
Reverse for 'page' with keyword arguments '{'path': '/my_site/'}' not found. 1 pattern(s) tried: ['notifications\\/(?P<path>[^/]+)\\Z']
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您知道第一页的URL名称,
则可以简单地使用:
否则,必须将上一页的URL添加到第二页模板的上下文中,以便在该模板中使用它。如何做到这取决于您的风格。例如,您可以以某种方式将访问的页面的日志保留在客户端或服务器端,并使用该集合来确定上一页。
If you know the url name of the first page,
then you can simply use:
Otherwise, you must add the url of the previous page to the context of the second page's template in order to use that in that template. How to do that depends on your style. For instance, you can somehow keep a log of the visited pages on the client side or server side, and use that collection to determine the previous page.