当我尝试删除时出现此错误:'str'对象不可调用?

时间:2019-08-19 11:22:50

标签: django-views

Please refer this link for traceback我正在尝试通过其ID删除用户对象,但是显示了一些错误。

def employe_delete(request,id=None):
    user = get_object_or_404(User,id=id)
    if request.method == 'POST':
        user.delete()
        return HttpResponseRedirect(reverse('employe_list'))
    else:
        conext = {}
        conext['user'] = user
        print(conext)
        return render(request, 'employee/delete.html', conext)
{% extends 'base.html' %}

{% block content %}
<h2> {{user.first_name}} {{user.last_name}} </h2>    
<form method="POST">{% csrf_token %}
    
    <p>Are you sure, You want to delete this employee</p>
    
    <button type="submit">Yes</button>

</form>
    
{% endblock content%}

当我尝试删除用户时,出现此错误:'str'对象不可调用

1 个答案:

答案 0 :(得分:0)

我已经将OneToOneField与用户一起使用,但是提到on_delete ='models.CASCADE'是我的错误。 models.CASCADE不应为字符串。