<p>I want to use the Django template engine in my (Python) code, but I'm not building a Django-based web site.  How do I use it without having a settings.py file (and others) and having to set the DJANGO_SETTINGS_MODULE environment variable?</p>

<p>If I run the following code:</p>

<pre><code>&gt;&gt;&gt; import django.template
&gt;&gt;&gt; from django.template import Template, Context
&gt;&gt;&gt; t = Template('My name is {{ my_name }}.')
</code></pre>

<p>I get:</p>

<pre><code>ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
</code></pre>

Any particular reason you want to use Django's templates? Both
Jinja
and
Genshi
are, in my opinion, superior.
If you really want to, then see the
Django documentation on
```
settings.py
```
. Especially the section "Using settings without setting
```
DJANGO_SETTINGS_MODULE
```
". Use something like this:
```
```
from django.conf import settings
settings.configure (FOO='bar') # Your settings go here
```
```