I wrote a signal in my django project, inside I want to send an email with the full path of my website. But to do so, I need to get the request object inside the signal, how could I do that? Thanks.
@receiver(pre_save, sender=AccessRequest)
def email_if_access_true(sender, instance, **kwargs):
#How can I get the full path of my website here?
pass
If you don’t have access to the request object, you can use the get_current() method of the Site model’s manager.
you need to ensure that you defined
SITE_ID=1
in your settingsPut following code in your
pre_save
signal receiver:You can generate absolute url to your website in email by passing required context variables to template. If
access_request
is instance in your case and there is one get_abosulte_url() method in yourAccessRequest
model, then following line in email template will give you absolute url.Reference - PasswordResetForm in
django.contrib.auth.form
.