在内部服务器上设置Django(os.environ()无法正常工作?) [英] Setting up Django on an internal server (os.environ() not working as expected?)

查看:643
本文介绍了在内部服务器上设置Django(os.environ()无法正常工作?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在内部的公司服务器上设置Django。 (没有外部连接到互联网。)

I'm trying to setup Django on an internal company server. (No external connection to the Internet.)

查看服务器安装文档,看来在Apache的共享托管服务提供商上运行Django 方法似乎是在这种情况下最有可能的工作。

Looking over the server setup documentation it appears that the "Running Django on a shared-hosting provider with Apache" method seems to be the most-likely to work in this situation.

这是服务器信息:


  • 无法安装 mod_python

  • 无root访问

  • 服务器是SunOs 5.6

  • Python 2.5

  • Apache / 2.0.46

  • 我已经安装了Django和 flup )使用 - 前缀选项(再次阅读我可能应该使用--home,但是目前它不似乎很重要)

  • Can't install mod_python
  • no root access
  • Server is SunOs 5.6
  • Python 2.5
  • Apache/2.0.46
  • I've installed Django (and flup) using the --prefix option (reading again I probably should've used --home, but at the moment it doesn't seem to matter)

我已经添加了 .htaccess 文件和 mysite.fcgi 文件到我的根目录,如 here
当我从服务器运行 mysite.fcgi 脚本时,我得到我的预期输出(正确的站点HTML输出)。但是,尝试从浏览器访问它时不会。

I've added the .htaccess file and mysite.fcgi file to my root web directory as mentioned here. When I run the mysite.fcgi script from the server I get my expected output (the correct site HTML output). But, it won't when trying to access it from a browser.

似乎可能是 PYTHONPATH 设置,因为我使用前缀选项。

It seems that it may be a problem with the PYTHONPATH setting since I'm using the prefix option.

我注意到,如果我从命令行运行 mysite.fcgi 而不设置 PYTHONPATH enviornment变量会引发以下错误:

I've noticed that if I run mysite.fcgi from the command-line without setting the PYTHONPATH enviornment variable it throws the following error:

prompt$ python2.5 mysite.fcgi 
 ERROR:
 No module named flup   Unable to load
 the flup package.  In order to run
 django   as a FastCGI application, you
 will need to get flup from  
 http://www.saddi.com/software/flup/  
 If you've already   installed flup,
 then make sure you have it in your
 PYTHONPATH.

我添加了 sys.path.append(prefixpath) os.environ ['PYTHONPATH'] = prefixpath mysite.fcgi ,但是如果我在命令行中将enviornment变量设置为空,那么运行 mysite.fcgi ,我仍然收到以上错误。

I've added sys.path.append(prefixpath) and os.environ['PYTHONPATH'] = prefixpath to mysite.fcgi, but if I set the enviornment variable to be empty on the command-line then run mysite.fcgi, I still get the above error.

这里有一些命令行结果: p>

Here are some command-line results:

>>> os.environ['PYTHONPATH'] = 'Null'
>>>
>>> os.system('echo $PYTHONPATH')
Null
>>> os.environ['PYTHONPATH'] = '/prefix/path'
>>>
>>> os.system('echo $PYTHONPATH')
/prefix/path
>>> exit()
prompt$ echo $PYTHONPATH
Null

它看起来像Python正在设置变量OK,但变量只适用于脚本内部。 Flup似乎以.egg文件的形式分发,我的猜测是,egg实现不考虑由 os.environ ['key'] = value (?)至少在通过 - 前缀选项进行安装时。

It looks like Python is setting the variable OK, but the variable is only applicable inside of the script. Flup appears to be distributed as an .egg file, and my guess is that the egg implementation doesn't take into account variables added by os.environ['key'] = value (?) at least when installing via the --prefix option.

我不太熟悉.pth文件,但似乎easy-install.pth文件是指向flup的文件:

I'm not that familiar with .pth files, but it seems that the easy-install.pth file is the one that points to flup:

import sys; sys.__plen = len(sys.path)
./setuptools-0.6c6-py2.5.egg
./flup-1.0.1-py2.5.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sy
s.path[p:p]=new; sys.__egginsert = p+len(new)

看起来它正在做一些有趣的事情,无论如何编辑这个或添加一些东西给我的代码,所以它会发现flup?

It looks like it's doing something funky, anyway to edit this or add something to my code so it will find flup?

推荐答案

在你的设置你必须指向实际的蛋文件,不是egg文件所在的目录。它应该看起来像:

In your settings you have to point go actual egg file, not directory where egg file is located. It should look something like:

sys.path.append('/path/to/flup/egg/flup-1.0.1-py2.5.egg')

这篇关于在内部服务器上设置Django(os.environ()无法正常工作?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆