使用jQuery的GET请求无法在DJango中工作

时间:2014-07-06 23:04:25

标签: jquery ajax django

我试图在django中删除一个简单的帖子, 问题是我的视图函数应该使用来自request.GET的数据甚至没有被调用(虽然不确定:()

这是我的代码:

view.py:

@login_required
def delete_blog(request) :
    idNum = None
    if request.method == 'GET' :
        idNum = request.GET['GET_ID']

    if idNum :
        obj = AuthPost.objects.filter(id=idNum) 
        obj.title = "" # i know it should delete it , not just change the title , only did this for test 
        obj.save()
    return HttpResponse("test") #again , just for testing purposes , should return something more valuable i suppose ! :) 

urlCONF:

url(r'^blog/delete_blog/' , delete_blog , name='delete_blog' ) ,

JS:

$(document).ready(function(){
    /*alert("js working") ;*/

    $('.delete').click( function(){
        var idNum ;
        idNum = $(this).attr('data-id') ; /* each button has a data-id attribute , this part works fine */ 
        alert(idNum) ; /* everything is fine , till here , the alert call outputs the correct id */ 
        $.get('/blog/delete_blog/' , {GET_ID : idNum} , function (data) {
            alert(data) ; /* nothing happens here */ 
        }) ;
        $(this).hide(1000) ;
    }) ;
}) ;

最后,当我点击一个带有class =&#34的按钮时,删除" ,页面将提醒该帖子的ID,并且......关于它的内容,没有别的,似乎忽略了视图delete_post(request)。
谢谢:)

更新: /.manage.py runserver日志中的一行可能对此有帮助:

"GET /blog/delete_blog/?GET_ID=5 HTTP/1.1"

0 个答案:

没有答案