from http://duooluu.iteye.com/blog/267956
参考:http://docs.djangoproject.com/en/dev/topics/install/#installing-development-version
以下内容根据上面的文档和网上资料整理一个完整步骤,方便参考
1. 获取最新Django,放到~/python路径下
svn co http://code.djangoproject.com/svn/django/trunk/ ~/python/django-trunk
2. 创建软连接
首先查看SITE-PACKAGES-DIR: python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
$ python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
/usr/lib/python2.5/site-packages
$ export SITE-PACKAGES-DIR=/usr/lib/python2.5/site-packages
$ ln -s ~/python/django-trunk/django-trunk/django $SITE-PACKAGES-DIR/django
$ ln -s ~/python/django-trunk/django/bin/django-admin.py /usr/local/bin
现在我们就可以在任意目录执行django-admin.py startproject xx了
3 创建工程
$ pwd
~/share
$ django-admin.py startproject test
4 现在来试试看
$ python
Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from django.template import Template, Context
>>> t=Template('Simple Test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/PIL/__init__.py", line 164, in __init__
File "/usr/lib/python2.5/site-packages/PIL/__init__.py", line 28, in __getattr__
File "/usr/lib/python2.5/site-packages/PIL/__init__.py", line 57, in _import_settings
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
>>>
根据报告的错误到网上找到了一篇文章:http://blog.csdn.net/mooninday/archive/2008/10/17/3092023.aspx
现在按这篇文章的方法来做
方法一:
>>> from django.template import Template, Context
>>> from django.conf import settings
>>> settings.configure()
>>> t = Template('My name is {{ my_name }}.')
>>> c = Context({'my_name': 'Daryl Spitzer'})
>>> t.render(c)
ok通过
方法二:
先确定python的路径
$ which python2.5
/usr/bin/python2.5
$ export PYTHONPATH=/usr/bin/python2.5:~/share
$ export DJANGO_SETTINGS_MODULE=test.settings
其中:~/share是django工程test所在的路径
测试一下
>>> from django.template import Template, Context
>>> from django.conf import settings
>>> t = Template('My name is {{ my_name }}.')
>>> c = Context({'my_name': 'Daryl Spitzer'})
>>> t.render(c)
ok通过
在Ubuntu中将
export PYTHONPATH=/usr/bin/python2.5:~/share
export DJANGO_SETTINGS_MODULE=test.settings
加到~/.profile文件中,每次登录就自动设置了