ACTUALIZACIÓN
Acorde a las recomendaciones dadas he cambiado ligeramente la definición de mi URL especificando el nombre del argumento o keyword argument que estoy pasando.
Mi función es:
def contact_owner_offer(request, lodging_offer_owner_email, user_interested_email, slug):
user = request.user
print("a", lodging_offer_owner_email, user_interested_email, slug)
if user.is_authenticated:
print('Send email')
mail_subject = 'Interesados en tu oferta'
context = {
'lodging_offer_owner_email': lodging_offer_owner_email,
# usuario dueño de la oferta TO
'offer': slug,
# oferta por la que se pregunta
'user_interested_email': user_interested_email,
# usuario interesado en la oferta
'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)
La definición de mi URL ha quedado así:
url(r'^contact-to-owner/(?P<lodging_offer_owner_email>[\w.@+-]+)/from/'
r'(?P<interested_email>[\w.@+-]+)/(?P<slug>[\w-]+)/$',
contact_owner_offer,
name='contact_owner_offer'
),
En mi template html ha quedado asi, el valor del parámetro slug, lo tomo a través del context_object_name que defino en la clase HostingOfferDetailView
por lo cual queda lodgingofferdetail.slug
:
<div class="contact">
<a class="contact-button" href="{% url 'host:contact_owner_offer' lodging_offer_owner_email=lodging_offer_owner_email interested_email=user_interested_email slug=lodgingofferdetail.slug %}">
<img src="{% static 'img/icons/contact.svg' %}" alt="">
<span>Contactar</span>
</a>
</div>
Y al posicionarme sobre el botón obtengo en el url el valor de los parámetros que estoy manejando
Solo que cuando le doy clic a ese botón, vuelvo al mismo error:
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/[email protected]/from/[email protected]/apartacho/
Exception Value: contact_owner_offer() got an unexpected keyword argument 'interested_email'
rror que tengo es ahora un NoReverseMatch
Exception Type: NoReverseMatch at /host/lodging-offer/apartacho/
Exception Value: Reverse for 'contact_owner_offer' with arguments '()' and keyword arguments '{'email': '[email protected]', 'interested_email': '[email protected]', 'lodging_offer_title': ''}' not found. 1 pattern(s) tried: ['host/contact-to-owner/(?P<lodging_offer_owner_email>[\\w.@+-]+)/from/(?P<interested_email>[\\w.@+-]+)/(?P<lodging_offer_title>[\\w-]+)/$']