Returning Wrong Base URL using frappe.utils.get_url()

Hello,

When I execute frappe.utils.get_url() in the bench console, it works properly. However, when I include this function in an email template, I get the wrong base URL. What could be causing this issue, and what are the possible solutions?

Recently I found the solution for this issue. If we set the host_name using the command:

bench --site {{site_name}} set-config host_name {{correct_domain_name}}

and then test again, it returns the correct base URL. When we test from the bench console, the function seems to work because it takes the URL from the current request or environment. But when we use this inside an email template, the code runs in a background job, so it always reads the base URL from the site configuration instead of the active browser request. I think this is the main reason why the URL was coming wrong earlier. For now, setting the host_name fixed the issue for me. I am not sure whether this is the most optimized way, but it works as a stable solution.

1 Like