[Answer]-Django while deleting entry getting error local variable 'delete' referenced before assignment

1👍

fixed as good as i could…as Daniel said…there are tooo many logic errors.

template

<a href = '/remove/{{ object_to_delete.id }}/'>remove</a>

view

from django.contrib.auth.decorators import login_required

@login_required #only allow deletion for authenticated users
def removerequest(request,id):
    get_objects=Todos.objects.get(pk=id) #get the todo object

    if request.method =='POST': # if form is submitted
        delete= get_objects.delete() # delete the shit
        return HttpResponseRedirect('/profile/') # return to profile URL
    # else
    context = {'object_to_delete': get_objects} # pass the todo object to the context
    return render_to_response('remove.html',context,context_instance=RequestContext(request)) #return all

Leave a comment