My django url is not working, I get a ReverseMatch error:
Reverse for 'activation_mail' with arguments '()' and keyword arguments '{u'activation_key': '1c38a44d216a51c26e65d789a3d8af2677cebebd', u'email': u'[email protected]', u'site_url': 'http://127.0.0.1:8000'}' not found. 1 pattern(s) tried: [u'accounts/mails/(P<activation_key>[0-9a-zA-Z]{40})/(P<email>[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+[.][a-zA-Z0-9-.]+)/(P<site_url>.*)/$']
The error happens when a user registers to the website. After entering a captcha code, the error occurs when trying to send a confirmation email to the user address.
urls.py:
urlpatterns = patterns(
url(r'^mails/(P<activation_key>[0-9a-zA-Z]{40})/(P<email>[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+[.][a-zA-Z0-9-.]+)/(P<site_url>.*)/$', TemplateView.as_view(template_name='accounts/mails/activation_email.html'), name='activation_mail'),
)
The mail is sent from the view that triggers the following function in the model...
models.py:
class SignupProfile(models.Model):
objects = SignupManager()
user = models.ForeignKey(settings.AUTH_USER_MODEL, unique=True,
verbose_name=_("utilisateur"))
activation_key = models.CharField(_("clef d'activation"), max_length=40)
def send_activation_email(self, request):
activation_url = reverse(
'accounts:activation',
kwargs={'activation_key': self.activation_key})
ctx = Context({'site_url': settings.SITE_URL,
'activation_key': self.activation_key,
'email': self.user.email})
html_tpl = get_template('accounts/mails/activation_email.html')
html_content = html_tpl.render(ctx)
msg = EmailMultiAlternatives(subject, text_content,
settings.DEFAULT_FROM_EMAIL,
[self.user.email])
msg.attach_alternative(html_content, 'text/html')
msg.send()
The error happens in the template used for the mail...
index.html:
<a href="{% url 'accounts:activation_mail' activation_key=activation_key email=email site_url=site_url %}" target="_blank">View this email in your browser</a>
I have used http://pythex.org/, the regex works.
What's the error?
views.pyisn't a view, it's logic to send email. Is that the entirety of your mainurls.pyfile? It should be setting up aurlpatternsvariable to hold those urls. It's not possible to answer completely without seeing the values you are using for the keyword variables.