title: Keep the id of an object after a redirection. Django
body: <p>In order to pass a function with arguments inside one of my template, I used a hidden input that redirects to a view where the function is (the function is used to delete a user the user is "following"). This view then redirects to the previous page thanks to a HttpResponseRedirect(reverse('myview', args=[a number])).</p>
  
  <p>The thing is that the page I redirect to needs an argument (a number). And I would like the user to be redirected to the exact page where he was.</p>
  
  <p>Here is my template:</p>
  
  <pre><code>    &lt;form method="post" action="{% url projet.views.remove_relationship %}"&gt;
      {% csrf_token %}
      &lt;input type="hidden" name="remove_relationship" value="{{ user.id }}"&gt;
      &lt;input type="submit" value="delete" /&gt;
  </code></pre>
  
  <p>And the view:</p>
  
  <pre><code>   def remove_relationship(request):
        user = request.user
        if request.method == 'POST':
          user_id = request.POST['remove_relationship']
          user_id= int(user_id)
          user_name = User.objects.get(id=user_id)
          user.userprofile.remove_relationship(person=user_name.userprofile, status=1)
       return HttpResponseRedirect(reverse('myoriginalview', args=[A NUMBER]))
  </code></pre>
  
  <p>The page where the user comes from is like: www.mysite/myoriginalview/ANUMBER. I want to redirect him to this exact page</p>
  
  <p>In the original view, the number corresponds to an object id. (match.id). </p>
  
  <p>So what I wan't to do is getting the match.id of my original view, pass it in my view remove_relationship in order to use it in "args=[match.id]".</p>
  
  <p>So how do I get this ID from my original view and pass it into my new view?</p>
  
  <p>Here is what I tried:</p>
  
  <p>in my models.py:</p>
  
  <pre><code>@models.permalink
  def get_absolute_url_remove_relationship(self):
      return ('remove_relationship', (), {'dub_id': self.id})
  </code></pre>
  
  <p>use it in my template:</p>
  
  <pre><code>&lt;form method="post" action="{{get_absolute_url_remove_relationship}}"&gt;
      {% csrf_token %}
      &lt;input type="hidden" name="remove_relationship" value="{{ user.id }}"&gt;
      &lt;input type="submit" value="delete" /&gt;
  </code></pre>
  
  <p>In my view:</p>
  
  <pre><code>def remove_relationship(request, match_id=None):
  match_id= int(match_id)
  user = request.user
  if request.method == 'POST':
      user_id = request.POST['remove_relationship']
      user_id= int(user_id)
      user_name = User.objects.get(id=user_id)
      user.userprofile.remove_relationship(person=user_name.userprofile, status=1)
  
  return HttpResponseRedirect(reverse('terrain', args=[match_id]))
  </code></pre>
  
  <p>And I do the necessary modifications in my url.py</p>
  
  <p>So when the user clicks on the button "delete" to delete a user he is following, the redirection works well, but the user is not deleted. It looks like the function is not used anymore, while when I used {%url projet.views.remove_relationship %}, the user was deleted, but there was no redirection.</p>
  
  <p>Any help would be very welcome.</p>
  
  <p>PS: The question comes after an other question I asked before (http://stackoverflow.com/questions/13233794/function-with-arguments-in-a-template-django). I opened a new topic in order to be clearer.</p>