1

我在 django 的一个模板中使用了 jquery 对话框作为删除操作的确认,但问题是当我将数据发布到视图时,我invalid regular expression flag d在调试 html 代码时得到了“”,问题出在这一行:

url : /certificates/delete/

这是我的代码:

模板 :

function openDialog(id){

        $( "#dialog-confirm" ).dialog({
          resizable: true,
          height:140,
          modal: true,
          buttons: {
            "Delete This Entry": function() {
            $.ajax({
                type: "POST",
                    url: {% url delete_id %},
                    data: {'id': id},
                    success: function() {
                        $( this ).dialog( "close" ); 
                    }
                });
              $( this ).dialog( "close" );
            },
            Cancel: function() {
              $( this ).dialog( "close" );
            }
          }
        });
    }

意见:

def delete_id(request):
     id = request.POST.get('id', None) 

网址:

url(r'^delete/', views.delete_id,name='delete_id')
4

2 回答 2

1

您正在尝试在服务器端生成删除 url,但 ID 是在客户端处理的。

考虑将其移至 POST 数据,而不是 URL 的“id”参数部分:

def delete_id(request):
     id = request.POST.get("id", None)
     if id is not None:
         print 'delete'

url(r'^delete/', views.delete_id,name='delete_id')

应用这些更改将使您的代码正常工作。

于 2013-08-16T13:48:41.350 回答
0

我认为您需要像这样更正您的 url 声明:

url(r'^delete/', entries.views.delete_id,name='delete_id')

在你的视野中写下这个

id = request.POST.get('id', None)

该错误消息还表明它无法映射参数。

于 2013-08-16T13:40:36.863 回答