Get the host name in Python

It is difficult to know from which environment the mail was sent when running in various environments or when there are multiple application servers.

So send it with the host name in the subject of the email. Since the host name can be obtained with the socket module, send an email using this as a prefix.

socket

settings.py


from socket import gethostname
EMAIL_SUBJECT_PREFX = '[%s]' % gethostname()

os Or you can get it from uname of os module.

settings.py


import os
EMAIL_SUBJECT_PREFIX = '[%s]' % os.uname()[1]

platform Similarly in the platform module.

settings.py


import platform
EMAIL_SUBJECT_PREFIX = '[%s]' % platform.uname()[1]

Recommended Posts

Get the host name in Python
How to get the variable name itself in python
Get the desktop path in Python
Get the script path in Python
Get the desktop path in Python
Get the EDINET code list in Python
Get date in Python
[Python] Get the files in a folder with Python
Get the weather in Osaka via WebAPI (python)
Get the caller of a function in Python
Get the X Window System window title in Python
Get YouTube Comments in Python
Get last month in python
Download the file in Python
Find the difference in Python
Get Terminal size in Python
Explicitly get EOF in python
Get Evernote notes in Python
Get Japanese synonyms in Python
How to get the number of digits in Python
[Python] Get the numbers in the graph image with OCR
[python] Get the list of classes defined in the module
Get the result in dict format with Python psycopg2
Get the size (number of elements) of UnionFind in Python
Get the value selected in Selenium Python VBA pull-down
[Python] Get element by specifying name attribute in BeautifulSoup
Get the URL of the HTTP redirect destination in Python
I want to get the file name, line number, and function name in Python 3.4
Get Leap Motion data in Python.
Getting the arXiv API in Python
Get your heart rate from the fitbit API in Python!
Python in the browser: Brython's recommendation
Get data from Quandl in Python
Save the binary file in Python
Hit the Sesami API in Python
Get the MIME type in Python and determine the file format
Get the weather with Python requests
Get the weather with Python requests 2
In the python command python points to python3.8
Implement the Singleton pattern in Python
Get the number of specific elements in a python list
How to get the Python version
Get the file name saved in AWS S3 (1000 or more)
Get the value while specifying the default value from dict in Python
Get, post communication memo in Python
How to get the last (last) value in a list in Python
Hit the web API in Python
Automatically get the port where Arduino is stuck in Python
I wrote the queue in Python
Calculate the previous month in Python
Examine the object's class in python
Get the class name where the method is defined in the decorator
Access the Twitter API in Python
Get the index of each element of the confusion matrix in Python
Python Note: Get the current month
The first step in Python Matplotlib
Get started with Python in Blender
I wrote the stack in Python
Get the query string (query string) in Django
Get the host name of the host PC with Docker on Linux
Master the weakref module in Python