ERPNext Conference 2019* Blog

Get current sitename in multi tenant system


Hey there,

I need to know how to access global variables, like the current sitename in ERPNext / Frappe. Unfortunately I did not found any information for this.

This is very basic information, so I think, it should be mentioned somewhere.

Thank you in advance.

Changes made to py file show on all sites
from frappe.utils import get_site_name


@max_morais_dmm Thank you very much. Unfortunately, this doesn’t solve the problem, since I have to pass a parameter to get_site_name.

I tried to check the repository for the usage of get_site_name, but trying for example is empty.


I solved my problem as follows, but it’s probably not the perfect solution.

Instead of using get_site_name(), I used get_site_base_path(), which doesn’t need any parameters. The result was for example like the following


Of course, it’s not getting the site_name, but for my needs it was perfect. Maybe someone can tell us how to get erp.mysite.local instead, without having to slice the string.



Try this

Only if the domain name and site name are same.


I didn’t try, but I am sure it would work as well.

I just didn’t know the path to the request.



Full solution:

import get_site_name method

from frappe.utils import get_site_name

get the site_name

site_name = get_site_name(

Is there function returns the current site url

I got to the point, that I need the full url with a prefix.

If the site is ssl secured, it has to be https, if it’s not, it has to be http. If API requests go to http, the reply on a https site is moved permanently, which will lead to the fact, that the api call will not be successful.

Any ideas?


Note about this:

This will not work, if your code is executed by for example a scheduled event. For that, I still have to use:


Better solutions are appreciated.


Below is the solution to get site name for ERP.

from frappe.utils import cstr

get the site_name
site_name = cstr(


Works well, thank you