位置参数缺少“状态”

时间:2019-11-17 05:37:46

标签: django python-3.6

在Django中:

re_path(r'^accept_friend_request(?P<uidb64>[0-9A-Za-z_\-]+)/$', accept_friend_request, name = 'accept_friend_request')

如何在模板的urlre_path的字符串模式中将状态作为参数添加?

<a class="btn btn-primary" href="{% url 'accept_friend_request' uidb64=uid %}">Accept</a>

这是我使用的代码:

def accept_friend_request(request, uidb64, status):
    """Accept button will lead to entry in database as accepted and reject button will lead to entry in database as rejected  based on status flag"""
    uid = urlsafe_base64_decode(uidb64).decode()
    friend_user = User.objects.get(pk=Friend.to_user.id)
    f = Friend.objects.filter(friend_id=friend_user)
    if f:
       f.status = status
       f.save()
       return request, "users/friend_list.html", {"uid": uidb64, "status": status}`
    else:
       return render(request, 'blog/base.html')

先谢谢您

1 个答案:

答案 0 :(得分:0)

# your url should include status

re_path(r'^accept_friend_request(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<status>[\w-]+)/$', accept_friend_request, name = 'accept_friend_request')