title: Typeerror for file deletion from database in django
body: <p>I'm trying to get together code that uploads and deletes photos from a django/bootstrap carousel, as well as a database.  However, I can't seem to get past this error: </p>
  
  <pre><code>TypeError at /alzheimers/delete
  
  delete() takes exactly 2 arguments (1 given)
  </code></pre>
  
  <p>Can anyone help me?  I'm kind of a noob at django, and writing this code is like pulling teeth, so any help would be greatly appreciated.</p>
  
  <p>My code:
  Carousel.html:</p>
  
  <pre><code>{% load staticfiles %}
  {% load filename %}
  
  &lt;div class="container"&gt;
      &lt;div class="row"&gt;
          &lt;div class="col-md-12"&gt;
              &lt;div id="myCarousel" class="carousel slide" data-ride="carousel"&gt;
  
  
                  &lt;div class="carousel-inner" role="listbox"&gt;
                      {% for document in documents %}
   &lt;div class="item {% if forloop.first %} active {% endif %}"&gt; 
      &lt;div class="row"&gt;
        &lt;div class="col"&gt;
          &lt;li&gt;&lt;a href = "{{document.docfile.url}}"&gt;{{document.docfile.name}}&lt;/a&gt;&lt;/li&gt;
          &lt;img src = "{{STATIC_URL}}img/{{document|filename}}" &gt;
  &lt;p align="center"&gt;&lt;form style="text-align:center" action="{% url 'webportal:delete' %}" method="post" enctype="multipart/form-data"&gt;
              {% csrf_token %}
  &lt;p&gt;{{ form.non_field_errors }}&lt;/p&gt;
              &lt;p&gt;{{ form.Document.label_tag }} {{ form.Document.help_text }}&lt;/p&gt;
              &lt;p&gt;
                  {{ form.Document.errors }}
                  {{ form.Document.docfile }}
              &lt;/p&gt; 
              &lt;p&gt;&lt;input type="submit" value="Delete" /&gt;&lt;/p&gt;
          &lt;/form&gt;&lt;/p&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    {% endfor %}
                  &lt;/div&gt;
                  &lt;a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"&gt;
                      &lt;span class="glyphicon glyphicon-chevron-left"&gt;&lt;/span&gt;
                      &lt;span class="sr-only"&gt;Previous&lt;/span&gt;
                  &lt;/a&gt;
                  &lt;a class="right carousel-control" href="#myCarousel" role="button" data-slide="next"&gt;
                      &lt;span class="glyphicon glyphicon-chevron-right"&gt;&lt;/span&gt;
                      &lt;span class="sr-only"&gt;Next&lt;/span&gt;
                  &lt;/a&gt;
              &lt;/div&gt;
              &lt;!-- /.carousel --&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;form action="{% url 'webportal:carousel' %}" method="post" enctype="multipart/form-data"&gt;
              {% csrf_token %}
              &lt;p&gt;{{ form.non_field_errors }}&lt;/p&gt;
              &lt;p&gt;{{ form.docfile.label_tag }} {{ form.docfile.help_text }}&lt;/p&gt;
              &lt;p&gt;
                  {{ form.docfile.errors }}
                  {{ form.docfile }}
              &lt;/p&gt;
              &lt;p&gt;&lt;input type="submit" value="Upload" /&gt;&lt;/p&gt;
          &lt;/form&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>Views.py:</p>
  
  <pre><code>from django.shortcuts import render
  from django.shortcuts import render, redirect, get_object_or_404
  from django.contrib.auth import authenticate, login
  from webportal.views.authentication import LoginForm
  from django.shortcuts import render_to_response
  from django.template import RequestContext
  from django.http import HttpResponseRedirect
  from django.http import HttpResponse
  from django.core.urlresolvers import reverse
  from django.conf import settings
  from webportal.forms.forms import DocumentForm
  from webportal.models import Document, DeleteForm
  is_server = True
  def delete(request, my_id):
      Deleted=get_object_or_404(Document, docfile=my_id)
      if request.method=='POST':
          form=DeleteForm(request.POST, instance=Deleted)
          if form.is_valid():
              Deleted.delete()
              return HttpResponseRedirect('http://127.0.0.1:8000/alzheimers/')
      else:
          form=DeleteForm(instance=Deleted)
      return render_to_response(
          'webportal/index.html',
          {'documents': documents, 'form': form,},
          context_instance=RequestContext(request)
      )        
  
              # Redirect to the document list after POST
  def carousel(request):
      # Handle file upload
      if request.method == 'POST':
          form = DocumentForm(request.POST, request.FILES)
          if form.is_valid():
              newdoc = Document(docfile = request.FILES['docfile'])
              newdoc.save()
  
              # Redirect to the document list after POST
              return HttpResponseRedirect('http://127.0.0.1:8000/alzheimers/')
  
  
  
  else:
  
  
  
   form = DocumentForm() # A empty, unbound form
  # Load documents for the list page
  documents = Document.objects.all()
  #documents=DocumentForm().
  # Render list page with the documents and the form
  return render_to_response(
      'webportal/index.html',
      {'documents': documents, 'form': form,},
      context_instance=RequestContext(request)
  )
  </code></pre>
  
  <p>Models.py:</p>
  
  <pre><code>class Document(models.Model):
      docfile = models.ImageField(upload_to='webportal/static/img/')
  class DeleteForm(ModelForm):
      class Meta:
          model=Document
          fields=[]
  </code></pre>
  
  <p>Forms.py:</p>
  
  <pre><code>class DocumentForm(forms.Form):
      docfile = forms.ImageField(label='Select a file', help_text='max. 42 megabytes')
  </code></pre>
  
  <p>urls.py:</p>
  
  <p>url(r'^delete', views.delete, name="delete"),</p>