Get_url in notifications (email) returns localhost

frappe.get_url in notifications (email) returns localhost. It seems that it is getting the value from the host_name in the site_config.

However, it cannot be set to the actual URL as the “localhost” is a solution to a a few pdf issues. For instance, need it so that the pdf will not generate very slowly, and also so that print format pdf attachments in workflow emails will work. Another one is for setting background images in pdfs.

Only workaround I can think of is to hard code the URL in the notifications, any better ideas?

you can just write the url manually . for example if the notification is leave application :
set url= “your_url/app/leave-application”+doc.name

What happens if you do use the correct url in site config, there shouldn’t be any such issues

This was what I was thinking as a last resort. But I have other environments, for example UAT, which has a different URL, and the link would be broken then.

These are some:

I have solved this. The solution is set the host_name to the real host/url AND also add the host/url to the host file.

bench --site mysite.com set-config host_name mysite.com
bench --site mysite.com add-to-hosts

Thanks for all the help!

Weird, your server couldn’t resolve DNS for the domain without adding to hosts?