来自前端的{Django-notification delete API

时间:2018-01-30 06:34:01

标签: django django-notification

你能帮我解决一下django-notification ??? 我能够实现它,但使用此API在前端停留
删除/(ΔP\ d +)/
当我调用此API时,我想提供的代替(?P \ d +)/

3 个答案:

答案 0 :(得分:1)

 url(r'^delete/(?P<id>\d+)$', views.delete, name='delete'),

def delete(request, id):
  if request.method == 'POST':
  if request.is_ajax():
    member = Member.objects.get(id = id)
   member.delete()
   messages.info(request, 'Member was deleted successfully!')
return JsonResponse({'data': 'bar'})

了解更多详情https://docs.djangoproject.com/en/1.11/topics/http/urls/

答案 1 :(得分:0)

ID基本上是通知ID,问题是我们首先使用slug函数转换它然后传递给API,这是id转换的代码

def id2slug(id):
    return id + 110909

答案 2 :(得分:0)

从github上的自述文件中:https://github.com/django-notifications/django-notifications,we可以看到,该值不是当您将id作为'slug'传递时不会删除的id thats。

urls.py(来自源代码) ... pattern(r'^delete/(?P<slug>\d+)/$', views.delete, name='delete') ...

每个Notifications在Notifications模型中都有一个slug属性,您可以将该属性传递给delete api来删除通知。