title: Django - How do I delete single database entries on button click?
body: <p>I'm trying to set up a user profile where you can enter skills. Entering the skills and save them in the databse already works. Now I want to give the user the opportunity to delete every single one of them with a button click. I tried posting the ID of each skill on button click in the URL and read it out in my view to get the item and delete it, but that does not work like I thought and I cant find out why...</p>
  
  <p><strong>MY VIEW</strong></p>
  
  <pre><code>def profile_settings(request, id=None):
  # get logged in user object from session
  user_id = request.user.id
  # get related userprofile
  userprofile = UserProfile.objects.get(pk=user_id)
  # get all skills of the userprofile
  user_skills = Skill.objects.filter(user=userprofile)
  
  if request.method == 'POST':
  
      form = SkillForm(request.POST)
  
      if 'delete-skill' in request.POST:
              if id:
                  print(id)
                  skill = Skill.objects.get(pk=id).delete()
  
      elif 'add-skill' in request.POST:
          if form.is_valid():
              # get data from form
              name = form.cleaned_data['name']
              category = form.cleaned_data['category']
              rating = form.cleaned_data['rating']
              # create new skill object for a user
              new_skill = Skill(name=name, category=category, rating=rating, user=userprofile)
              # save it in the database
              new_skill.save()
  
  else:
      form = SkillForm()
  return render(request, 'profile-settings.html', {'skillform': form, 'existing_skills': user_skills})
  </code></pre>
  
  <p><strong>MY URLS</strong></p>
  
  <pre><code>urlpatterns = [
      url(r'^landing', views.landing, name='landing'),
      url(r'^neuigkeiten', views.news, name='news'),
      url(r'^profileinstellungen/', views.profile_settings, name='profileinstellungen'),
      url(r'^profileinstellungen/(?P&lt;id&gt;\d+)/$', views.profile_settings, name='profileinstellungen'),
  ]
  </code></pre>
  
  <p><strong>MY TEMPLATE</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>{% extends 'base.html' %}
  
  {% block content %}
      &lt;form method="post" style="margin-top: 300px"&gt;
          {% csrf_token %}
          {{ skillform }}
  
          &lt;input type="submit" value="Hinzufügen" name="add-skill "/&gt;
  
      &lt;/form&gt;
  
      &lt;form method="post"&gt;
          {% csrf_token %}
          &lt;ul&gt;
              {% for skill in existing_skills %}
                  &lt;li&gt;{{ skill.name }}&lt;/li&gt;
                  &lt;input href="{% url 'profileinstellungen' id=skill.id%}" type="submit" value="Löschen" name="delete-skill"/&gt;
              {% endfor %}
          &lt;/ul&gt;
      &lt;/form&gt;
  
  {% endblock %}</code></pre>
  </div>
  </div>
  </p>
  
  <p>It does not post the ID of the skill in the URL. Is there an alternative approach?</p>