8👍
You can use the SERVER_EMAIL
or EMAIL_SUBJECT_PREFIX
setting.
In your settings.py:
import socket
SERVER_ADMIN = 'alerts+{0}@mydomain.com'.format(socket.gethostname())
or
import socket
EMAIL_SUBJECT_PREFIX = '[my_django_app - {0}] '.format(socket.gethostname())
-1👍
If you want the httpd server name you can get it from the request.
site_name = request.META['SERVER_NAME']
This isn’t necessarily the hostname of the machine, but it is the server name alias in the Apache/IIS directive for the site. Alternately, if you absolutely need the server’s machine name:
import socket
host_name = socket.gethostname()
UPDATE:
Now that you have the hostname of the particular server, you can add that to the error emails in a couple of ways. You could write your own error notification system, or as @sdolan mentioned you can change the SERVER_ADMIN
or EMAIL SUBJECT_PREFIX
directives in settings.py
. Or, you can change your SERVER_EMAIL
directive. You can use the "{0}".format(socket.gethostname())
syntax, or you can use the string joining of a list of strings "".join(string_parts_list)
.
# settings.py
import socket
SERVER_EMAIL = "".join(['webmaster@', socket.gethostname(), '.com'])
- [Django]-Django – set_language view giving me a "Page not found" error
- [Django]-Django 'Key(field)=() is duplicated'
- [Django]-Create new application in django
-2👍
Python’s socket.gethostname()
(socket docs) is one method.
from socket import gethostname; print gethostname()
You can also get some parameters from os.uname()
(os docs)
import os; print os.uname()[1]
Would get the ‘nodename’.
- [Django]-How to test admin change views?
- [Django]-How to localize datetime in Django view code (with BST)?
- [Django]-How to calculate execution time of a view in Django?
- [Django]-South appears to be loading initial_data.json twice
- [Django]-Running Django Python Server in AWS