簡體   English   中英

在Openshift上安裝/創建Django應用

[英]Installing / Creating a Django app on Openshift

我正在將應用程序遷移到openshift的過程-但是,我似乎找不到太多(任何)文檔來實際使應用程序在PaaS中運行。 一個主要問題是知道我應該處理創建應用程序時默認的wsgi.py文件-在這種情況下為Python3.3。

這是我所做的:

  1. rhc命令創建一個python3.3應用程序。
  2. 克隆存儲庫。
  3. 編輯setup.py並取消注釋Django的要求(請參見下面的鏈接)。
  4. 嘗試以下鏈接的wsgi.py建議(更改python版本)

如何在OpenShift上配置Django?

現在,在推送之后,我可以看到django作為必需項被setup.pysetup.py更改)。 但是我無法確定wsgi.py文件中應該包含的wsgi.py -即使是用作模板的基本應用程序也非常有用,但我根本找不到。 wsgi.py使用以下wsgi.py會出現以下錯誤:

#!/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/python3.3/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()

這是錯誤消息:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Apache/2.2.15 (Red Hat) Server at name-name.rhcloud.com Port 80

這是我得到的日志文件:

[Thu Jul 03 13:15:59 2014] [error] [client 127.8.250.1]     % (self.SETTINGS_MODULE, e)
[Thu Jul 03 13:15:59 2014] [error] [client 127.8.250.1] ImportError: Could not import settings 'name.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named 'name'
80.241.77.253 - - [03/Jul/2014:13:15:59 -0400] "GET /favicon.ico HTTP/1.1" 500 622 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"

一個基本的settings.py文件也將很有用!

os.environ['DJANGO_SETTINGS_MODULE'] = 'PROJECTNAME.settings' ->您必須將PROJECTNAME更改為您的項目文件夾名稱,並與下一個相同。

順便說一句,檢查一下,看看是否有幫助: http : //django.zone/posts/3以防您遇到更多錯誤。

如果您需要基本的模板應用程序,則可以查看此github repo https://github.com/argaen/djangozone ,這是一個足以理解所有內容的博客。 您也可以檢查此倉庫: https : //github.com/openshift/django-example

我的wsgi.py中的以下內容:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings.prod")

application = get_wsgi_application()

並且項目根目錄中的requirements.txt文件足以使django應用程序正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM