问题描述
我最近试图在OpenShift上导出一个Django项目,但是没有成果。我发现的唯一解决方案是预先构建的解决方案(如 https://github.com/openshift/django我花了几个小时尝试调整自己的项目,但总是有一个内部服务器错误。
那么,如何在openshift上设置django?
我终于弄清楚了。首先要做的是启动一个opensshift应用程序并编辑setup.py文件:
rhc app create -a APPNAME - t python-2.6
cd APPNAME
vim setup.py
您需要取消注释install_requires = ['Django> = 1.3']
然后你可以提交服务器:
git commit -a -m初始化
git push
默认情况下,它安装django 1.4,但我认为您可以在setup.py中选择具有正确安装要求的其他版本。无论如何,您必须在计算机和服务器上运行相同的django版本以进行以下操作。
创建您的django项目:
cd wsgi
django-admin.py startproject PROJECTNAME
然后,您必须编辑文件应用程序,通过以下方式替换整个内容:
!/ usr / bin / python
import os,sys
os.environ ['DJANGO_SETTINGS_MODULE'] ='PROJECTNAME.settings'
sys.path.append(os.path .join(os.environ ['OPENSHIFT_REPO_DIR'],'wsgi',
'PROJECTNAME'))
virtenv = os.environ ['APPDIR'] +'/ virtenv /'
os.environ ['PYTHON_EGG_CACHE'] = os.path.join(virtenv,'lib / python2.6 / site-packages')
virtualenv = os.path.join(virtenv,'bin / activate_this
try:
execfile(virtualenv,dict(__ file __ = virtualenv))
除了IOError:
pass
#
#重要信息:放入其他任何附件在这条线以下。如果放在
#行之上,可能需要的库不会在您的可搜索路径
#
from django.core.handlers import wsgi
application = wsgi.WSGIHandler( )
最后,您可以提交修改:
cd ..
git add。
git commit -a -m项目创建
git push
你应该看到django欢迎页面。
现在,您可以编辑设置并导入django应用,而不需要不必要的内容
I recently tried to export a Django project on OpenShift, but fruitlessly. The only solutions I found were "prebuilt" ones (such as https://github.com/openshift/django-example).
I spent some hours trying to adapt it to my project but I always got an Internal Server Error.
So, how to setup django on openshift?
I finally figured it out. The first thing to do is to start an openshift app and edit the setup.py file :
rhc app create -a APPNAME -t python-2.6
cd APPNAME
vim setup.py
You need to uncomment "install_requires=['Django>=1.3']"
Then you can commit to the server :
git commit -a -m "Initialization"
git push
By default, it installs django 1.4 but I think you can choose another version with the correct install requirement in setup.py. Anyway, you'll have to run the same django version on your computer and the server for the following.
Create your django project :
cd wsgi
django-admin.py startproject PROJECTNAME
Then you'll have to edit the file application, replace the whole content by :
#!/usr/bin/python
import os, sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'PROJECTNAME.settings'
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi',
'PROJECTNAME'))
virtenv = os.environ['APPDIR'] + '/virtenv/'
os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python2.6/site-packages')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
pass
#
# IMPORTANT: Put any additional includes below this line. If placed above this
# line, it's possible required libraries won't be in your searchable path
#
from django.core.handlers import wsgi
application = wsgi.WSGIHandler()
Finally, you can commit the modifications :
cd ..
git add .
git commit -a -m "Project Creation"
git push
You should see the django welcome page.Now you can edit the settings and import your django apps without unwanted content
这篇关于如何在OpenShift上配置Django?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!