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

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

问题描述

我试图安装Django的公司内部的服务器上。 (没有外部连接到因特网。)

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

展望服务器设置文档在它看来,<一个href=\"http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-with-apache\"相对=nofollow>与阿帕奇方法的共享主机提供商运行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 ) - 的 preFIX选项(读我再次也许应该使用过 - 回家,但目前它似乎并不重要)

  • 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 提到文件到我的根Web目录<一个href=\"http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-with-apache\"相对=nofollow>此处。
当我从服务器上运行的 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 设置,因为我使用的是preFIX选项问题。

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.

下面是一些命令行的结果:

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中是设置变量确定,但是变量只适用脚本的内部。 Flup似乎是分布为.egg文件,我的猜测是,鸡蛋的实施并没有考虑到由添加os.environ ['关键'] =值至少当通过安装(?) - preFIX 选项

我没那么熟悉.pth文件,但似乎易于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)

它看起来像它做一些时髦的,反正编辑此或添加点东西给我code所以它会找到flup?

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

推荐答案

在你的设置,你必须去点实际鸡蛋文件,而不是目录,其中鸡蛋文件的位置。它看起来应该是这样的:

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天全站免登陆