1👍
✅
You can iterate through all your Contacts on the index page with their names between anchor tags and href as url to subscribe with a parameter lead_id as persons id
lets say you sent the context to index page as contacts
{% for i in contacts%}
<a href='{% url 'subscribe' lead_id=i.id %}'> {{i.name}}</a>
{% endfor %}
Now inside your subscribe function
@login_required(login_url="/login/")
def subscribe(request, lead_id):
lead = Lead.objects.get(pk=lead_id)
subject = 'Introduction'
message = 'Good morning,'
recipient = lead.email
send_mail(subject,
message, EMAIL_HOST_USER, [recipient], fail_silently = False)
return render(request, 'subscribe/success.html', {'recipient': recipient, 'lead': lead})
Source:stackexchange.com