python - 我想将两个 id 从 .html 发布到视图
问题描述
html 文件我想把两个 id 带到views.py 我能得到吗?
path('yorum_sil/<int:id>',views.yorum_sil,name="yorum_sil")
我想做如下代码
path('yorum_sil/<int:comment_id> and <int:post_id>',views.yorum_sil,name="yorum_sil")
解决方案
这是可能的,尽管您不应该使用这样的空格。例如,您可以使用如下斜杠:
path('yorum_sil/<int:comment_id>/<int:post_id>',views.yorum_sil,name="yorum_sil")
您的视图函数(此处yorum_sil
)当然需要接受这两个参数,例如:
# app/views.py
def yorum_sil(request, comment_id, post_id):
# ...
return ...
如果执行反向查找,则需要传递这两个参数。例如在这样的模板中:
<a href="{% url 'yorum_sil' comment_id=14 post_id=25 %}">some_link</a>
如果我正确翻译了 yorum sil,则表示删除评论,请注意通常 GET 请求不应有副作用。为了删除/创建/...一个实体,您应该使用 POST 请求。
推荐阅读
- python - catalina 10.51.1 python3 w brew 或 xcode-select
- android - 如何在android datepicker中获取月份的第一个和最后一个日期
- django - 将views.py中的视图合并为一个视图?
- c++ - 你愿意就我的程序程序给我反馈吗?
- c# - 当使用 Fody.PropertyChanged 将文本添加到文本框时,为什么我的按钮没有启用?
- swiftui - 如何在 SwiftUI 中显示整个 CALayer 内容?
- c++ - c++ 类对象与另一个类的序列化
- asp.net - 获取“用户'TestUser'登录失败。” 在通过 ASP.Net 程序连接到 DB 期间
- javascript - 请问有什么方法可以将这些数据处理成所需的格式吗?
- c# - HttpPostedFileBase 有错误 (MVC) 红色下划线