Maybe it is not very beautiful, but it is possible to do it as a one-liner:
```python
message = Template(self.error_messages.get(code, self.error_messages[error_code])
```