django前端删除与修改按钮代码

1,前端样式:

2,前端代码:

2.1文件下载与引入:

https://github.com/qiwsir/DjangoPracticeProject/tree/master/mysite2/static/js 

layer.js与skin目录复制到本地项目./static/js

2.2前端代码:

{% load staticfiles %}

<td><a name="edit" href="javascript:" οnclick="edit_column(this,{{ column.id }},{{ column.column }})"><span class="glyphicon glyphicon-pencil"></span></a>
<a name="delete" href="javascript:" οnclick="del_column(this,{{ column.id }},{{ column.column }})"><span class="glyphicon glyphicon-trash" style="margin-right: 20px;"></span></a>
</td>
<script type="text/javascript" src="{% static "js/jquery.js" %}"></script>
<script type="text/javascript" src="{% static "js/layer.js" %}"></script>
<script type="text/javascript">
function edit_column(the,column_id,column_name){
{#        var name = $(the).parent("tr").children("td").eq(1).text(); 另一种方法#}
        var index = layer.open({
            type:1,
            skin:"layui-layer-rim",
            area:["400px","200px"],
            title:"编辑栏目",
            content:'<div class="text-center" style="margin-top:20px"><p>请输入新的栏目名称</p>'+
            '<p><input type="text" id="new_name" value="'+column_name+'"></p></div>',
            btn:['确定','取消'],
            yes: function(index,layero){
                column_new_name = $('#new_name').val();
                $.ajax({
                    url: '{% url 'article:rename_article_column' %}',
                    type:'POST',
                    data: {'column':column_new_name,'column_id':column_id},
                    success:function (e){
                    if(e=="1"){
                        parent.location.reload();
                        layer.msg("good");
                    }else{
                        layer.msg("新名称没有保存,修改失败。");
                    }
                }
                });
            },
            btn2: function(index,layero){
                layer.close(index);
            }
        }
        )
    }
</script>

3,后端代码

@csrf_exempt
@require_POST
@login_required(login_url='/account/login/')
def rename_column(request):
    column_name = request.POST['column']
    column_id = request.POST['column_id']
    try :
        line = ArticleColumn.objects.get(id=column_id)
        line.column = column_name
        line.save()
        return HttpResponse(1)
    except:
        return HttpResponse(0)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值