0

I want to add an email into a path in Django. I did this code but I don't know how take the variable called email after username place.

path('validate_email/<slug:username>/(?P<email>[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})/<slug:token>', views.validate_email, name="validate_email")
Tysaic
  • 31
  • 5
  • If can send me any documentation to read more about the regex please I will be very congratulate with your. – Tysaic Jan 09 '18 at 21:19
  • https://stackoverflow.com/a/28982264/8150371 , https://stackoverflow.com/a/14485817/8150371 – Stack Jan 09 '18 at 21:21
  • Sorry i dont explain very well. The validate email is when i send a email to confirm the account when you are sing up. – Tysaic Jan 09 '18 at 21:23

1 Answers1

1

You cannot use a regex with path(). If you want to use a regex you'll need to use re_path() or url().

It might be easier to use simply <email> in the URL pattern, then you can validate the email in the view.

 path('validate_email/<slug:username>/<email>/<slug:token>', views.validate_email, name="validate_email")
Daniel Roseman
  • 541,889
  • 55
  • 754
  • 786
Alasdair
  • 253,590
  • 43
  • 477
  • 449
  • simply replace url with re_path if you don't want to do additional validation in view: https://docs.djangoproject.com/en/2.0/ref/urls/#django.urls.re_path – PhoebeB Aug 13 '18 at 09:47