I’m on Chapter 4: Templates of the Django tutorial, and I’m trying to run the following in an Emacs inferior mode using Python:
>>> from django import template
>>> t = template.Template('My name is {{ name }}.')
>>> c = template.Context({'name': 'Adrian'})
>>> print t.render(c)
My name is Adrian.
>>> c = template.Context({'name': 'Fred'})
>>> print t.render(c)
My name is Fred.
But I get the error here.
A quick search suggests that I should do be setting my DJANGO_SETTINGS_MODULE like so:
>>> import os
>>> os.environ["DJANGO_SETTINGS_MODULE"] = "settings.py"
However, I run into this error:
ImportError: Could not import settings 'settings.py' (Is it on sys.path?): No module named settings.py
I’m using Fedora 16. How do I correctly resolve this problem?
You can do this in the
python manage.py shell, since that would havesettings.pyin.directory.Otherwise:
Consider
settings.pyjust another python library and you need to ensure its added tosys.pathand then you can do as follows :This sets up the settings to your environment. [ This is the right way ]
There is no secret recipe in
settings.pyand since django in itself is a library to python, so it could not be default set any paths to yoursys.pathunless imported and executed – as I suggested.