title: Passing multiple parameters to Django URL - unexpected keyword argument
body: <p>How to can I address this <code>NoReverseMatch</code> error?</p>
  
  <p>Context</p>
  
  <p>I want to document this question as much as possible in order to be able to detail the origin of the problem.</p>
  
  <p>I have a model named <code>LodgingOffer</code>, to create a lodging offer and have the detail their information</p>
  
  <pre><code>class LodgingOffer(models.Model):
  
      # Foreign Key to my User model      
      created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
  
      ad_title = models.CharField(null=False, blank=False,
          max_length=255, verbose_name='Título de la oferta')
  
      slug = models.SlugField(max_length=100, blank=True)
  
      # ... Another fields ...
  
      def __str__(self):
          return "%s" % self.ad_title
  
      def get_absolute_url(self):
          return reverse('host:detail', kwargs = {'slug' : self.slug })
  
  # I assign slug to offer based in ad_title field,checking if slug exist
  def create_slug(instance, new_slug=None):
      slug = slugify(instance.ad_title)
      if new_slug is not None:
          slug = new_slug
      qs = LodgingOffer.objects.filter(slug=slug).order_by("-id")
      exists = qs.exists()
      if exists:
          new_slug = "%s-%s" % (slug, qs.first().id)
          return create_slug(instance, new_slug=new_slug)
      return slug
  
  # Brefore to save, assign slug to offer created above.
  def pre_save_article_receiver(sender, instance, *args, **kwargs):
      if not instance.slug:
          instance.slug = create_slug(instance)
  
  pre_save.connect(pre_save_article_receiver, sender=LodgingOffer)
  </code></pre>
  
  <hr>
  
  <p>For this model, I have a  DetailView named <code>HostingOfferDetailView</code> .</p>
  
  <p>An important objective I want to pursue and for which I ask this question is that in the detail view of an <code>LodgingOffer</code> object, I should be able to contact the owner of that offer (object <code>LodgingOffer</code> - user who created it -) so that another interested user can apply to it.</p>
  
  <p>I would like that in the detail view for the <code>LodgingOffer</code> object be able to contact the offer owner (object <code>LodgingOffer</code> - user who created it -) so others users interested could apply to it</p>
  
  <p>For this purpose, I have <code>contact_owner_offer()</code> function, is where I send an email to the owner of this offer.</p>
  
  <p>I'm doing all using the <code>HostingOfferDetailView</code> detail view like this:</p>
  
  <pre><code>class HostingOfferDetailView(DetailView):
      model = LodgingOffer
      template_name = 'lodgingoffer_detail.html'
      context_object_name = 'lodgingofferdetail'
  
      def get_context_data(self, **kwargs):
          context = super(HostingOfferDetailView, self).get_context_data(**kwargs)
          user = self.request.user
  
          # Get the related data offer
          #lodging_offer_owner = self.get_object()
          lodging_offer_owner_full_name = self.get_object().created_by.get_long_name()
  
          lodging_offer_owner_email = self.get_object().created_by.email
  
          lodging_offer_title = self.get_object().ad_title
          user_interested_email = user.email
          user_interested_full_name = user.get_long_name()
  
          # Send to context email of owner offer and user interested in offer
          context['user_interested_email'] = user_interested_email
          context['lodging_offer_owner_email'] = lodging_offer_owner_email
  
          # Send the data (lodging_offer_owner_email
          # user_interested_email and lodging_offer_title) presented 
          # above to the contact_owner_offer function
          contact_owner_offer(self.request, lodging_offer_owner_email, user_interested_email, lodging_offer_title)
  
          return context
  </code></pre>
  
  <p>My <code>contact_owner_offer()</code> function receives these offer parameters and sends an email to the owner of the offer or the publisher, as follows: </p>
  
  <pre><code>def contact_owner_offer(request, lodging_offer_owner_email, user_interested_email, lodging_offer_title):
      user = request.user
      if user.is_authenticated:
          # print('Send email')
          mail_subject = 'Interest in your offer'
  
          context = {
              'lodging_offer_owner_email': lodging_offer_owner_email,
              # User owner offer - TO send email message
  
              'offer': lodging_offer_title,
              # offer for which a user asks 
  
              'user_interested_email': user_interested_email,
              # Interested user offer
  
              'domain': settings.SITE_URL,
              'request': request
          }
  
          message = render_to_string('contact_user_own_offer.html', context)
          #to_email = lodging_offer_owner.email,
  
          send_mail(mail_subject, message, settings.DEFAULT_FROM_EMAIL,
                    [lodging_offer_owner_email], fail_silently=True)
  </code></pre>
  
  <p>I have done this as a test and so far everything is as I wanted, and the result is that when I enter the URL of a detailed offer object <code>LodgingOffer</code>, an email is sent to the owner of that offer.</p>
  
  <p>What I would like that the offer detail template has a button with contains <strong>"Contact the owner of the offer"</strong> and when any user who presses it send an email to the owner of the offer.</p>
  
  <p>To do this I defined a URL for <code>contact_owner_offer()</code> function and it has a link on the <code>href</code> attribute of a button in my template.</p>
  
  <p>The URL, (according to my understanding and this is where the doubt and the reason for my question resides) I have defined it according to the number of parameters that the <code>contact_owner_offer()</code> function receives.</p>
  
  <p>This means my URL must receive:</p>
  
  <ul>
  <li>The offer owner's email address </li>
  <li>The e-mail address of the user interested in the offer </li>
  <li>The title of the offer, <strong>although for this I'm
  sending you the slug of that title, I don't know if that's correct</strong>.</li>
  </ul>
  
  <p>So, according to the above, I've created this URL:</p>
  
  <pre><code>url(r'^contact-to-owner/(?P&lt;email&gt;[\w.@+-]+)/from/'
          r'(?P&lt;interested_email&gt;[\w.@+-]+)/(?P&lt;slug&gt;[\w-]+)/$',
          contact_owner_offer, name='contact_owner_offer'),
  </code></pre>
  
  <p>Then, in my template, I generate an html button where I call this URL sending them their respective parameters that expect:</p>
  
  <pre><code>&lt;div class="contact"&gt;
      &lt;a class="contact-button" href="{% url 'host:contact_owner_offer' email=lodging_offer_owner_email interested_email=user_interested_email slug=lodgingofferdetail.slug %}"&gt;
          &lt;img src="{% static 'img/icons/contact.svg' %}" alt=""&gt;
          &lt;span&gt;Contact owner offer&lt;/span&gt;
      &lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>What happens to me is that when I enter the offer detail template and click on the <strong>Contact owner offer</strong> reference button immediately above, I get the following error message:</p>
  
  <pre><code> TypeError: contact_owner_offer() got an unexpected keyword argument 'email'
  [10/Oct/2017 01:04:06] "GET /host/contact-to-owner/botibagl@gmail.com/from/ces@ces.edu.co/apartacho/ HTTP/1.1" 500 77979  
  </code></pre>
  
  <p>My traceback is here</p>
  
  <pre><code>Traceback:
  
  File "/home/bgarcial/.virtualenvs/hostayni/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
    42.             response = get_response(request)
  
  File "/home/bgarcial/.virtualenvs/hostayni/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
    187.                 response = self.process_exception_by_middleware(e, request)
  
  File "/home/bgarcial/.virtualenvs/hostayni/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
    185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
  
  Exception Type: TypeError at /host/contact-to-owner/botibagl@gmail.com/from/botibagl@gmail.com/apartacho/
  Exception Value: contact_owner_offer() got an unexpected keyword argument 'email'
  </code></pre>
  
  <p>What I don't understand, is because it tells me that my URL doesn't wait for an argument called <code>email</code> which is where I pass the parameter <code>email=lodging_offer_owner_owner_email</code> through the button in the template.</p>
  
  <p>I appreciate any guidance
  Best Regards</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>According to the <a href="https://stackoverflow.com/users/8482471/rajkris">@RajKris</a> and <a href="https://stackoverflow.com/users/104349/daniel-roseman">@Daniel</a> recommendations I've changed slightly my URL regex, specifying the name of the keyword argument which I am passing. The URL stay of this way:</p>
  
  <pre><code>url(r'^contact-to-owner/(?P&lt;lodging_offer_owner_email&gt;[\w.@+-]+)/from/'
          r'(?P&lt;interested_email&gt;[\w.@+-]+)/(?P&lt;slug&gt;[\w-]+)/$',
          contact_owner_offer,
          name='contact_owner_offer'
      ),
  </code></pre>
  
  <p>This mean, I am naming the url parameters of the same way in which I've named the parameters that <code>contact_owner_offer()</code> receive.</p>
  
  <p>And when I  enter the offer detail template and click on the <strong>Contact owner offer</strong> reference button I get the <code>NoReverseMatch</code> error </p>
  
  <pre><code>Template error:
  In template /home/bgarcial/workspace/hostayni_platform/hosts/templates/lodgingoffer_detail.html, error at line 193
     Reverse for 'contact_owner_offer' with arguments '()' and keyword arguments '{'email': 'botibagl@gmail.com', 'interested_email': 'botibagl@gmail.com', 'slug': 'apartacho'}' not found. 1 pattern(s) tried: ['host/contact-to-owner/(?P&lt;lodging_offer_owner_email&gt;[\\w.@+-]+)/from/(?P&lt;interested_email&gt;[\\w.@+-]+)/(?P&lt;slug&gt;[\\w-]+)/$']   183 :                                &lt;/tr&gt;
     184 :                                &lt;tr&gt;
     185 :                                    &lt;td&gt;{{ lodgingofferdetail.room_value }}&lt;/td&gt;
     186 :                                    &lt;td&gt;{{ lodgingofferdetail.additional_description }}&lt;/td&gt;
     187 :                                    &lt;td&gt;{{ lodgingofferdetail.lodging_offer_owner_email }}&lt;/td&gt;
     188 :                                &lt;/tr&gt;
     189 :                            &lt;/tbody&gt;
     190 :                        &lt;/table&gt;
     191 :                    &lt;/div&gt;
     192 :                    &lt;div class="contact"&gt;
     193 :                        &lt;a class="contact-button" href=" {% url 'host:contact_owner_offer' email=lodging_offer_owner_email interested_email=user_interested_email slug=lodgingofferdetail.slug %} "&gt;
     194 :                            &lt;img src="{% static 'img/icons/contact.svg' %}" alt=""&gt;
     195 :                            &lt;span&gt;Contactar&lt;/span&gt;
     196 :                        &lt;/a&gt;
     197 :                    &lt;/div&gt;
  </code></pre>
  
  <p>The general traceback is here:</p>
  
  <pre><code>File "/home/bgarcial/.virtualenvs/hostayni/lib/python3.6/site-packages/django/urls/resolvers.py" in _reverse_with_prefix
    392.             (lookup_view_s, args, kwargs, len(patterns), patterns)
  
  Exception Type: NoReverseMatch at /host/lodging-offer/apartacho/
  Exception Value: Reverse for 'contact_owner_offer' with arguments '()' and keyword arguments '{'email': 'botibagl@gmail.com', 'interested_email': 'botibagl@gmail.com', 'slug': 'apartacho'}' not found. 1 pattern(s) tried: ['host/contact-to-owner/(?P&lt;lodging_offer_owner_email&gt;[\\w.@+-]+)/from/(?P&lt;interested_email&gt;[\\w.@+-]+)/(?P&lt;slug&gt;[\\w-]+)/$']
  </code></pre>
  
  <p>How to can I address this <code>NoReverseMatch</code> error? </p>