Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one include the server hostname in a django error email?

Tags:

python

django

The title pretty much sums up the question. I have a django based site load balanced across multiple servers. As much as all the servers should be identical, $#%& happens... It would be really useful if the error emails django sends included the hostname of the server. How would this be achieved?

p.s. It's django 1.3 on python 2.7.2 if that makes any difference.

UPDATE:

I can get the hostname, that's not the issue. The problem is how to add it to the error emails.

like image 535
Endophage Avatar asked Feb 28 '26 13:02

Endophage


1 Answers

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())
like image 114
Sam Dolan Avatar answered Mar 03 '26 03:03

Sam Dolan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!