[Answer]-Typeerror for file deletion from database in django

1👍

You are POSTing your object id through a form while your delete view expects it as an argument (my_id). Change it to:

def delete(request):
    if request.method=='POST':
        my_id = request.POST.get('id')
        Deleted=get_object_or_404(Document, id=my_id)
        ...

As a side note, the Python convention is to use lowercase names for objects. Consider renaming Deleted to deleted.

Update: You also seem to have omitted to include the id of the object to be deleted in your form. Put the following line somewhere between your <form> and </form> tags:

<input type="hidden" name="id" value="{{ document.id }}" />
👤Selcuk

Leave a comment