Reputation: 99
I am using Django template. I want to add multiple parameter in URL
currently I am passing only one parameter
my reset_password.html
Click on this link to reset your password
{% if htmlVersion %}
<div>
<a href="{{domain}}{% url 'pweuser:user_password_sms_reset' token %}">
{{domain}}{% url 'pweuser:user_password_sms_reset' token %}
</a>
</div>
{% else %}
{{domain}}{% url 'pweuser:user_password_sms_reset' token %}
{% endif %}
This link will expire in 15 minutes
my urls.py
url(r"^resetPasswordSms/(?P<token>[-\w_=]{28})/$", PasswordResetSmsView.as_view(), name="user_password_sms_reset",),
my views.py
t = loader.get_template("reset_password.html")
c = {"htmlVersion": True, "domain": settings.SITE_DOMAIN, "token": token.token}
htmlVersion = t.render(c)
c = {"htmlVersion": False, "domain": settings.SITE_DOMAIN, "token": token.token}
textVersion = t.render(c)
Here its is working good
in this I want to add more than 1 parameter. means here token is the 1st parameter and I need to add userId as 2nd parameter and need to pass in template..
how can i add multiple parameter in URL and template URL
Upvotes: 0
Views: 300
Reputation: 58
Here is how you can add multiple parameters in URL:
from django.urls import re_path
urlpatterns = [
re_path(r"^resetPasswordSms/(?P<userId>[0-9])/(?P<token>[-\w_=]{28})/$", PasswordResetSmsView.as_view(), name="user_password_sms_reset")
]
https://docs.djangoproject.com/en/3.1/topics/http/urls/#using-regular-expressions
and template URL:
{% url 'pweuser:user_password_sms_reset' token=value1 userId=value2 %}
https://docs.djangoproject.com/en/3.1/ref/templates/builtins/#url
If you have any questions about any part, you can refer to the link below that.
Upvotes: 1