Django Template Variable Failing as href Value

Viewed 48

I have created a Django template which serves as an email template for my app. Upon certain actions, a celery task sends an email from this template using Sendgrid. Previously I hard-coded the URLs but now I need them to be dynamic. I am passing the url string as a variable called profile_url. I know that the URL is formatted correctly because I am printing it before calling the send_mail() function. If I use the value like so it works:

<p>{{ profile_url }}</p>

However, when I use it as an href value the link renders unclickable:

<a
  href="{{ profile_url }}"
  target="_blank"
  style="
    text-decoration: none;
    color: #ffffff;
    line-height: 40px;
    display: block;
    "
>Go to your profile</a>

If anyone can assist me or at least point me in the right direction here I'd greatly appreciate it!

1 Answers
<a
  href="{{ modelname.profile_url }}"
  target="_blank"
  style="
    text-decoration: none;
    color: #ffffff;
    line-height: 40px;
    display: block;
    "
>Go to your profile</a>

you have to called field with its model name and i also assume that this profile_url is in models.URLField still getting error add your model

Related