免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5870 | 回复: 14
打印 上一主题 下一主题

哪位大哥有在浪点服务器上部署python+Django环境的经验啊,可否教我? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-08-12 21:29 |显示全部楼层 |倒序浏览
我按浪点的官方说明:
Python常见问题指南
1.Python采用何种方式运行?

浪点主机提供:
mod_python和fastcgi+Python两种方式运行python程序.

2.如何搭建Django站点?

(方法一)

mod_python模式

[.htaccess]
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE 项目.settings
PythonPath "['自定义django路径']+['项目所在目录'] + sys.path"
PythonDebug On

(方法二)

fastcgi+python模式下,您可以下载使用我们的django样例:

http://www.londit.cn/examples/pyexamples.tar.gz

[.htaccess]

AddHandler fastcgi-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ django.fcgi/$1 [QSA,L]

[django.fcgi]

#!/usr/bin/python
#-*-coding:UTF-8-*-#
import sys, os
projectName = 'py' #项目名称 如: "py"
pathAdd = os.path.dirname(os.path.abspath(__file__)) #项目所在目 如: /var/www/
projectPath = pathAdd + '/%s/' % (projectName) #项目路径 如:/var/www/py/
sys.path.insert(0,pathAdd);
sys.path.insert(0,"./");
os.chdir(projectPath)
os.environ["DJANGO_SETTINGS_MODULE"] = '%s.settings' % (projectName)
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

两种模式Django的环境均无法运行,我对环境部署完全没有头脑,哪位大哥能指导俺一下啊?
有什么需要特别注意的么?

论坛徽章:
0
2 [报告]
发表于 2009-08-13 07:10 |显示全部楼层
谢谢~~~我就是用那个例程来着,可是用浏览器访问我的目录打印出django.fcgi的源码来了,好像fcgi没有运行~

论坛徽章:
0
3 [报告]
发表于 2009-08-13 17:43 |显示全部楼层
是啊~~~~我不大明白~~~~~~~~

论坛徽章:
0
4 [报告]
发表于 2009-08-13 17:45 |显示全部楼层
[.htaccess]

AddHandler fastcgi-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ django.fcgi/$1 [QSA,L]


这个写法有错误么?
我对.htaccess文件配置没什么概念~~~

论坛徽章:
0
5 [报告]
发表于 2009-08-16 20:49 |显示全部楼层
我晕~~~谢谢楼上的老大!

这浪点可真够呛~我还问过客服,人家一句“对python环境已不提供技术支持”就给我顶回来了,nnd!

论坛徽章:
0
6 [报告]
发表于 2009-08-17 16:33 |显示全部楼层
楼上的老大,请问我俺您的博客步骤操作:
自定义Pythonhandler:

这里做的最核心的事情就相当于你运行source bin/activate,把Python运行环境切换为你自己的虚拟环境。

#myve.py activate_this = ‘/home/virtualhost/${username}/sandbox/bin/activate_this.py’ execfile(activate_this, dict(__file__=activate_this)) from django.core.handlers.modpython import handler


这一步是啥意思啊,我应该怎么操作啊?

论坛徽章:
0
7 [报告]
发表于 2009-08-17 16:41 |显示全部楼层
我晕,您的意思是不是建一个文件叫myve.py

#myve.py
activate_this = ‘/home/virtualhost/${username}/sandbox/bin/activate_this.py’
execfile(activate_this, dict(__file__=activate_this)) from django.core.handlers.modpython import handler
然后在.htaccess里引用啊~~~~


厄~~~我这理解力,还真不是一般的差啊

论坛徽章:
0
8 [报告]
发表于 2009-08-17 17:13 |显示全部楼层
我配置完了,报如下错误:
MOD_PYTHON ERROR

ProcessId:      2159
Interpreter:    'wayhome'

ServerName:     'www.flyzhu.cn'
DocumentRoot:   '/home/virtualhost/用户名/屏蔽/public_html'

URI:            '/pyapp/'
Location:       None
Directory:      '/home/virtualhost/用户名/屏蔽/public_html/pyapp/'
Filename:       '/home/virtualhost/用户名/屏蔽/public_html/pyapp/'
PathInfo:       ''

Phase:          'PythonHandler'
Handler:        'myve'

Traceback (most recent call last):

  File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1229, in _process_target
    result = _execute_target(config, req, object, arg)

  File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1128, in _execute_target
    result = object(arg)

  File "/var/lib/python-support/python2.6/django/core/handlers/modpython.py", line 228, in handler
    return ModPythonHandler()(req)

  File "/var/lib/python-support/python2.6/django/core/handlers/modpython.py", line 191, in __call__
    self.load_middleware()

  File "/var/lib/python-support/python2.6/django/core/handlers/base.py", line 31, in load_middleware
    for middleware_path in settings.MIDDLEWARE_CLASSES:

  File "/var/lib/python-support/python2.6/django/conf/__init__.py", line 28, in __getattr__
    self._import_settings()

  File "/var/lib/python-support/python2.6/django/conf/__init__.py", line 57, in _import_settings
    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)

ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.


MODULE CACHE DETAILS

Accessed:       Mon Aug 17 09:10:09 2009
Generation:     0

_mp_8af738322c2efd462425537e8e369fad {
  FileName:     '/home/virtualhost/用户名/屏蔽/public_html/pyapp/myve.py'
  Instance:     1 [IMPORT]
  Generation:   1
  Modified:     Mon Aug 17 09:07:48 2009
  Imported:     Mon Aug 17 09:10:09 2009

论坛徽章:
0
9 [报告]
发表于 2009-08-18 17:24 |显示全部楼层
非常感谢各位前辈哈~~我确实还没入门,只在win环境下自己配置过测试环境~~~
我现在的问题是报如下告警:
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

请问,这个变量在linux下怎么设置啊?
写进我的.profile配置文件?

论坛徽章:
0
10 [报告]
发表于 2009-08-18 17:32 |显示全部楼层
.htaccess文件中的这行不就是设置环境变量么

PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE pyapp.settings

[ 本帖最后由 imcncer 于 2009-8-18 17:34 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP