How to send link include id in email user in django?
Question:
please i need to help i send this lien http://127.0.0.1:8000/benevole/demande_participer/id:?/
in email user but id is not Read in email
Thanks in advance
---this is the urls.py
path('benevole/demande_participer/<int:id>', views.demande_participer, name='demande_participer'),
—— this is views.py =>
def demande_participer(request,id):
participers=Mission.objects.get(id=id)
benParticiper=User.objects.filter(username=request.user)
template=render_to_string('Association/email_template.html')
email=EmailMessage(
'Veuillez confirmer votre participation a la mission proposer',#header message
template, # h1
settings.EMAIL_HOST_USER,
[request.user.email],
)
email.fail_silenty=False
email.send()
—this is email_template.html
{% load crispy_forms_tags %}
{% block content %}
Confirmé la Participation
http://127.0.0.1:8000/benevole/demande_participer/id:?/
{% endblock %}
Answers:
You need to pass the context to the render to string method, let’s say you want the participers id in the email link
views.py
def demande_participer(request,id):
participers=Mission.objects.get(id=id)
benParticiper=User.objects.filter(username=request.user)
# Context here
context = {
"participers": participers,
}
# pass context in render_to_string
template=render_to_string('Association/email_template.html', context=context)
email=EmailMessage(
'Veuillez confirmer votre participation a la mission proposer',#header message
template, # h1
settings.EMAIL_HOST_USER,
[request.user.email],
)
email.fail_silenty=False
email.send()
——–email_template.html——-
{% load crispy_forms_tags %}
{% block content %}
Confirmé la Participation
<!-- in your Html {{participers.id}} -->
http://127.0.0.1:8000/benevole/demande_participer/{{benParticiper.id}}/
{% endblock %}
please i need to help i send this lien http://127.0.0.1:8000/benevole/demande_participer/id:?/
in email user but id is not Read in email
Thanks in advance
---this is the urls.py
path('benevole/demande_participer/<int:id>', views.demande_participer, name='demande_participer'),
—— this is views.py =>
def demande_participer(request,id):
participers=Mission.objects.get(id=id)
benParticiper=User.objects.filter(username=request.user)
template=render_to_string('Association/email_template.html')
email=EmailMessage(
'Veuillez confirmer votre participation a la mission proposer',#header message
template, # h1
settings.EMAIL_HOST_USER,
[request.user.email],
)
email.fail_silenty=False
email.send()
—this is email_template.html
{% load crispy_forms_tags %}
{% block content %}
Confirmé la Participation
http://127.0.0.1:8000/benevole/demande_participer/id:?/
{% endblock %}
You need to pass the context to the render to string method, let’s say you want the participers id in the email link
views.py
def demande_participer(request,id):
participers=Mission.objects.get(id=id)
benParticiper=User.objects.filter(username=request.user)
# Context here
context = {
"participers": participers,
}
# pass context in render_to_string
template=render_to_string('Association/email_template.html', context=context)
email=EmailMessage(
'Veuillez confirmer votre participation a la mission proposer',#header message
template, # h1
settings.EMAIL_HOST_USER,
[request.user.email],
)
email.fail_silenty=False
email.send()
——–email_template.html——-
{% load crispy_forms_tags %}
{% block content %}
Confirmé la Participation
<!-- in your Html {{participers.id}} -->
http://127.0.0.1:8000/benevole/demande_participer/{{benParticiper.id}}/
{% endblock %}