Variable with current sites IP and PORT?

Please help me to find variable that has my current site IP and port

frappe.utils.get_url()
Returns: erpnext.vm

Is not OK for me, I need IP and PORT:

Example:

http://192.168.88.182:8000
http://67.89.12.89:8000

You can use window.location to get host and port

in frappe module? How to call it?

In [3]: import frappe.window.location

ImportError Traceback (most recent call last)
/home/frappe/frappe-bench/apps/frappe/frappe/commands/utils.pyc in ()
----> 1 import frappe.window.location

ImportError: No module named window.location

window.location is javascript

try frappe.request.url in Python

1 Like

Not working for me. Look please to my error:

In [1]: from frappe import request

In [2]: print request.url

RuntimeError Traceback (most recent call last)
/home/frappe/frappe-bench/apps/frappe/frappe/commands/utils.pyc in ()
1 print request.url

/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/werkzeug/local.pyc in getattr(self, name)
341 if name == β€˜members’:
342 return dir(self._get_current_object())
β†’ 343 return getattr(self._get_current_object(), name)
344
345 def setitem(self, key, value):

/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/werkzeug/local.pyc in _get_current_object(self)
304 return getattr(self.__local, self.name)
305 except AttributeError:
β†’ 306 raise RuntimeError(β€˜no object bound to %s’ % self.name)
307
308 @property

RuntimeError: no object bound to request

request won’t work in python console it is werkzeug.local.LocalProxy

Oh but can’t find PORT and IP:

In [2]: import werkzeug

In [3]: print werkzeug.local.LocalProxy
<class β€˜werkzeug.local.LocalProxy’>

In [4]: print dir(werkzeug.local.LocalProxy)
[β€˜_LocalProxy__local’, β€˜abs’, β€˜add’, β€˜and’, β€˜call’, β€˜class’, β€˜cmp’, β€˜coerce’, β€˜complex’, β€˜contains’, β€˜copy’, β€˜deepcopy’, β€˜delattr’, β€˜delitem’, β€˜delslice’, β€˜dict’, β€˜dir’, β€˜div’, β€˜divmod’, β€˜doc’, β€˜enter’, β€˜eq’, β€˜exit’, β€˜float’, β€˜floordiv’, β€˜format’, β€˜ge’, β€˜getattr’, β€˜getattribute’, β€˜getitem’, β€˜getslice’, β€˜gt’, β€˜hash’, β€˜hex’, β€˜index’, β€˜init’, β€˜int’, β€˜invert’, β€˜iter’, β€˜le’, β€˜len’, β€˜long’, β€˜lshift’, β€˜lt’, β€˜mod’, β€˜module’, β€˜mul’, β€˜name’, β€˜ne’, β€˜neg’, β€˜new’, β€˜nonzero’, β€˜oct’, β€˜or’, β€˜pos’, β€˜pow’, β€˜radd’, β€˜rdiv’, β€˜rdivmod’, β€˜reduce’, β€˜reduce_ex’, β€˜repr’, β€˜rfloordiv’, β€˜rmod’, β€˜rmul’, β€˜rshift’, β€˜rsub’, β€˜rtruediv’, β€˜setattr’, β€˜setitem’, β€˜setslice’, β€˜sizeof’, β€˜slots’, β€˜str’, β€˜sub’, β€˜subclasshook’, β€˜truediv’, β€˜unicode’, β€˜xor’, β€˜_get_current_object’]

frappe.request.url is just a string.

In [1]: from urlparse import urlparse

In [2]: url1 = "http://67.89.12.89:8000"

In [3]: url0 = "http://192.168.88.182:8000"

In [4]: parsed_url1 = urlparse(url1)

In [5]: parsed_url1
Out[5]: ParseResult(scheme=u'http', netloc=u'67.89.12.89:8000', path=u'', params='', query='', fragment='')

In [6]: parsed_url1.netloc
Out[6]: u'67.89.12.89:8000'

In [7]: parsed_url1.netloc.split(":")
Out[7]: [u'67.89.12.89', u'8000']

In [8]: parsed_url0 = urlparse(url0)

In [9]: parsed_url0.netloc.split(":")
Out[9]: [u'192.168.88.182', u'8000']