2017-04-24 22 views
0

我有一個Django項目和結構如下,如何在本地運行的Django項目的Heroku

enter image description here

enter image description here

Procfile裏面,我有這樣的代碼,

web: gunicorn team-app.wsgi --log-file - 

這是requirements.txt,

appdirs==1.4.3 
coreapi==2.3.0 
coreschema==0.0.4 
dj-database-url==0.4.2 
Django==1.11 
django-allauth==0.31.0 
django-rest-auth==0.9.1 
django-rest-swagger==2.1.2 
djangorestframework==3.6.2 
gunicorn==19.7.1 
itypes==1.1.0 
Jinja2==2.9.6 
MarkupSafe==1.0 
oauthlib==2.0.2 
openapi-codec==1.3.1 
packaging==16.8 
pyparsing==2.2.0 
python-openid==2.2.5 
pytz==2017.2 
requests==2.13.0 
requests-oauthlib==0.8.0 
simplejson==3.10.0 
six==1.10.0 
uritemplate==3.0.0 
whitenoise==3.3.0 

env是本地安裝的virtualenv。當我在root文件夾,team-app進入並運行命令heroku local web,我得到以下錯誤,

enter image description here

enter image description here

所以,問題是ImportError: No module named team-app.wsgi,我相信Procfile的位置或有些東西是不正確的。該wsgi.py文件中的users_groups是如下,

""" 
WSGI config for users_groups project. 

It exposes the WSGI callable as a module-level variable named ``application``. 

For more information on this file, see 
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ 
""" 

import os 

from django.core.wsgi import get_wsgi_application 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "users_groups.settings") 

application = get_wsgi_application() 

如果需要,我可以提供額外的信息。如何解決這個問題?

+1

很難從截圖中看出來,但它看起來像'requirements.txt'和'Procfile'在一個子目錄中?他們[應該在](https://devcenter.heroku.com/articles/python-pip#the-basics)[root project directory](https://devcenter.heroku.com/articles/procfile)。它也看起來像你的整個Django應用程序在一個名爲'src /'的子目錄中;它可能也必須被提升到一個水平。通常我會用它作爲我的項目根目錄。你的Git倉庫是否處於'src /'級別或'team-app /'級別? – Chris

+0

'1.'' requirements.txt和Procfile'均位於'team-app'的頂層。 '2.'這是正確的,整個Django應用程序在'src'文件夾內。我不相信這是一個問題,或者它是? '''''Git'生活在'team-app /'層面。 我爲這個問題提供了一個新的「項目結構」圖片,以便於理解。 – Arefe

+1

當我第一次在Heroku上開始使用Django時,我記得不得不使用我的主Django目錄作爲我的項目根目錄。那是幾年前,所以也許它不再適用,但它是值得一試。嘗試將'Procfile'移動到'src /',然後'cd'到'src /',然後從那裏運行'heroku local web'('procfile'指'users_groups.wsgi')。 – Chris

回答

1

這裏有兩個問題。 首先是Django的相關:

ImportError: No module named team-app.wsgi

wsgi.py文件位於users_groups/目錄中,以便您的Procfile應引用users_groups.wsgi

web: gunicorn users_groups.wsgi --log-file - 

頂級目錄的名稱包含整個項目是無關緊要的。

第二個問題是與Heroku有關。 Heroku預計Django目錄將成爲您的存儲庫的根目錄。將Procfile移動到src/,然後運行heroku local web應該啓動並在本地運行。

當您部署到Heroku時,您必須確保您當前的src/目錄是您的根目錄。這可能意味着將一些文件移動到src/並在那裏重新創建/重構您的Git存儲庫,或者這可能意味着將當前在src/中的所有內容都移動到一個級別。

+0

它不起作用,我得到錯誤'ImportError:No module named users_groups.wsgi'。我認爲它應該是'project_name.wsgi'。 – Arefe

+0

我也試過類似'src.users_groups.wsgi'和'src.main.users_groups.wsgi'的版本。我想這個問題是圍繞它,但目前尚未解決。 – Arefe

相關問題