如何在ubuntu 下配置Django和apache + mod_python
-
- 帖子: 92
- 注册时间: 2005-03-26 0:02
如何在ubuntu 下配置Django和apache + mod_python
在ubuntu 下配置Django和apache + mod_python
在www.djangoproject.org下载django 0.91版本
http://www.djangoproject.com/download/
然后
tar xzvf Django-0.91.tar.gz
cd Django-0.91
sudo python setup.py install
接下来你进入到刚才所解压的django/bin目录下,运行
python django-admin.py startproject myproject,
他将会在你的bin目录下创建myproject目录,
myproject/
__init__.py
manage.py
settings.py
urls.py
这时候你需要修改一下
settings.py
DATABASE_ENGINE = 'mysql' # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
DATABASE_NAME = 'django' # Or path to database file if using sqlite3.
DATABASE_USER = 'root' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = 'localhost' # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = '3306' # Set to empty string for default. Not used with sqlite3.
按照你的不同情况设定不同的参数
然后你就可以执行
python manage.py runserver
Validating models...
0 errors found.
Starting server on port 8000 with settings module 'myproject.settings'.
Go to http://127.0.0.1:8000/ for Django.
Quit the server with CONTROL-C (Unix) or CTRL-BREAK (Windows).
你也可以通过指定端口的方式运行
python manage.py runserver 8080
到浏览器中访问一下吧
到现在只是做完第一步,我们还要让django在apache2下运行
你需要准备mod_python 和 python_mysql module或者其他的db module
然后
在/etc/apache2/httpd.conf或者site-avaible下也可,
添加
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myproject.settings
PythonPath "['/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/bin/'] + sys.path"
PythonDebug On
切记要按照我加了红色的这行去设定,否则系统找不到myproject.settings
这时候只要你
sudo apache2ctl -k restart
然后去浏览器中输入
http://localhost/mysite/就可以看到django的欢迎页面了
在www.djangoproject.org下载django 0.91版本
http://www.djangoproject.com/download/
然后
tar xzvf Django-0.91.tar.gz
cd Django-0.91
sudo python setup.py install
接下来你进入到刚才所解压的django/bin目录下,运行
python django-admin.py startproject myproject,
他将会在你的bin目录下创建myproject目录,
myproject/
__init__.py
manage.py
settings.py
urls.py
这时候你需要修改一下
settings.py
DATABASE_ENGINE = 'mysql' # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
DATABASE_NAME = 'django' # Or path to database file if using sqlite3.
DATABASE_USER = 'root' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = 'localhost' # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = '3306' # Set to empty string for default. Not used with sqlite3.
按照你的不同情况设定不同的参数
然后你就可以执行
python manage.py runserver
Validating models...
0 errors found.
Starting server on port 8000 with settings module 'myproject.settings'.
Go to http://127.0.0.1:8000/ for Django.
Quit the server with CONTROL-C (Unix) or CTRL-BREAK (Windows).
你也可以通过指定端口的方式运行
python manage.py runserver 8080
到浏览器中访问一下吧
到现在只是做完第一步,我们还要让django在apache2下运行
你需要准备mod_python 和 python_mysql module或者其他的db module
然后
在/etc/apache2/httpd.conf或者site-avaible下也可,
添加
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myproject.settings
PythonPath "['/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/bin/'] + sys.path"
PythonDebug On
切记要按照我加了红色的这行去设定,否则系统找不到myproject.settings
这时候只要你
sudo apache2ctl -k restart
然后去浏览器中输入
http://localhost/mysite/就可以看到django的欢迎页面了
- firehare
- 帖子: 2625
- 注册时间: 2005-04-10 16:54
- 来自: 温州大学
- 联系:
-
- 帖子: 74
- 注册时间: 2005-12-28 14:12
- 联系:
-
- 帖子: 74
- 注册时间: 2005-12-28 14:12
- 联系:
DJango不能在apache1.3里用么?
在ubuntu 5.10里有
--------
--------
可是安装了
libapache-mod-python
libapache-mod-python2.4
还需要安装mod-python么?
或者谁知道libapache-mod-python(或者libapache2-mod-python)
和mod-python有什么区别呢?
在ubuntu 5.10里有
--------
代码: 全选
username@colinux:/etc/apache2$ apt-cache search mod-python
libapache2-mod-python - An Apache module that embeds Python within the server
libapache2-mod-python-doc - An Apache module that embeds Python within the server
libapache2-mod-python2.4 - An Apache 2 module that embeds Python 2.4 within the server
libapache-mod-python - An Apache module that embeds Python within the server
libapache-mod-python-doc - An Apache module that embeds Python within the server
libapache-mod-python2.3 - An Apache module that embeds Python 2.3 within the server
libapache-mod-python2.4 - An Apache module that embeds Python 2.4 within the server
libapache2-mod-python2.3 - An Apache 2 module that embeds Python 2.3 within the server
可是安装了
libapache-mod-python
libapache-mod-python2.4
还需要安装mod-python么?
或者谁知道libapache-mod-python(或者libapache2-mod-python)
和mod-python有什么区别呢?
-
- 帖子: 68
- 注册时间: 2006-06-18 14:13
- 联系:
我在执行这步时出错,请问是什么原因呀。
root@huzi:~/MyDownloads/Django-0.91/django/bin# python django-admin.py startproject mytest
Traceback (most recent call last):
File "django-admin.py", line 2, in ?
from django.core import management
ImportError: No module named django.core
root@huzi:~/MyDownloads/Django-0.91/django/bin#
另外上一步执行python setup.py install时信息提示如下:
---------------------------------------------------------------------------
This script requires setuptools version 0.6a9 to run (even to display
help). I will attempt to download it for you (from
http://cheeseshop.python.org/packages/2.4/s/setuptools/), but
you may need to enable firewall access for this script first.
I will start the download in 15 seconds.
---------------------------------------------------------------------------
Downloading http://cheeseshop.python.org/packages/2 ... -py2.4.egg
Traceback (most recent call last):
File "setup.py", line 2, in ?
ez_setup.use_setuptools()
File "/root/MyDownloads/Django-0.91/ez_setup.py", line 82, in use_setuptools
egg = download_setuptools(version, download_base, to_dir, download_delay)
File "/root/MyDownloads/Django-0.91/ez_setup.py", line 130, in download_setuptools
src = urllib2.urlopen(url)
File "/usr/lib/python2.4/urllib2.py", line 130, in urlopen
return _opener.open(url, data)
File "/usr/lib/python2.4/urllib2.py", line 364, in open
response = meth(req, response)
File "/usr/lib/python2.4/urllib2.py", line 471, in http_response
response = self.parent.error(
File "/usr/lib/python2.4/urllib2.py", line 402, in error
return self._call_chain(*args)
File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain
result = func(*args)
File "/usr/lib/python2.4/urllib2.py", line 480, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found
请问我该如何解决!
root@huzi:~/MyDownloads/Django-0.91/django/bin# python django-admin.py startproject mytest
Traceback (most recent call last):
File "django-admin.py", line 2, in ?
from django.core import management
ImportError: No module named django.core
root@huzi:~/MyDownloads/Django-0.91/django/bin#
另外上一步执行python setup.py install时信息提示如下:
---------------------------------------------------------------------------
This script requires setuptools version 0.6a9 to run (even to display
help). I will attempt to download it for you (from
http://cheeseshop.python.org/packages/2.4/s/setuptools/), but
you may need to enable firewall access for this script first.
I will start the download in 15 seconds.
---------------------------------------------------------------------------
Downloading http://cheeseshop.python.org/packages/2 ... -py2.4.egg
Traceback (most recent call last):
File "setup.py", line 2, in ?
ez_setup.use_setuptools()
File "/root/MyDownloads/Django-0.91/ez_setup.py", line 82, in use_setuptools
egg = download_setuptools(version, download_base, to_dir, download_delay)
File "/root/MyDownloads/Django-0.91/ez_setup.py", line 130, in download_setuptools
src = urllib2.urlopen(url)
File "/usr/lib/python2.4/urllib2.py", line 130, in urlopen
return _opener.open(url, data)
File "/usr/lib/python2.4/urllib2.py", line 364, in open
response = meth(req, response)
File "/usr/lib/python2.4/urllib2.py", line 471, in http_response
response = self.parent.error(
File "/usr/lib/python2.4/urllib2.py", line 402, in error
return self._call_chain(*args)
File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain
result = func(*args)
File "/usr/lib/python2.4/urllib2.py", line 480, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found
请问我该如何解决!
-
- 帖子: 40
- 注册时间: 2006-08-01 14:42
- 联系:
其实在Linux下面和在Windows下面配置没有什么不同的,我觉得唯一不同的就是在Windows下面不能使用Apache2.2, 因为Mod_Python在Windows下面最多支持到Apache2.0系列;
欢迎访问我的网站http://www.china-django.com, 该网站使用Python.Django框架作的,不过服务器不是用的Mod_Python+Apache,而是使用的FastCGI+Apache
欢迎访问我的网站http://www.china-django.com, 该网站使用Python.Django框架作的,不过服务器不是用的Mod_Python+Apache,而是使用的FastCGI+Apache
-
- 帖子: 40
- 注册时间: 2006-08-01 14:42
- 联系:
另外补充一下, Django现在的最新版本是 0.95了,可以到Django的官方网站 http://www.djangoproject.com去下载;
还可以使用Subversion下载最新的,几乎每天都有更新的,下载命令:svn co http://code.djangoproject.com/svn/django/trunk/ 您自己的目录
其中 您自己的目录 替换为您自己要把django下载在那里的本地目录
还可以使用Subversion下载最新的,几乎每天都有更新的,下载命令:svn co http://code.djangoproject.com/svn/django/trunk/ 您自己的目录
其中 您自己的目录 替换为您自己要把django下载在那里的本地目录
- h0214
- 帖子: 10
- 注册时间: 2007-12-19 10:38
- 联系: