无法在AWS弹性Beanstalk上找到Django App的模块 [英] Cannot locate modules of Django App on AWS Elastic Beanstalk
问题描述
我正在尝试在AWS Elastic Beanstalk上运行一个Django应用程序,但是它似乎可能是一个PYTHONPATH或者virtualenv问题,而且我无法想象出来。
I'm trying to make a Django app run on AWS Elastic Beanstalk, but am stuck with what appears like it might be a PYTHONPATH or virtualenv problem, and I can't figure it out.
当我尝试在浏览器中加载一个页面时,我得到了黄色的Django错误屏幕(我仍然处于调试模式):
When I try to load a page in my browser, I get the yellow Django error screen (I'm still in debug mode):
Exception Value: No module named views.rest
Exception Location: /opt/python/current/app/project/urls.py in <module>, line 3
Python Executable: /opt/python/run/venv/bin/python
Python Version: 2.7.5
Python Path:
['/opt/python/run/venv/lib/python2.7/site-packages',
'/opt/python/current/app',
...
我的urls.py导入是:
My urls.py imports are:
from django.conf.urls import patterns, include, url
from django.contrib import admin
from myapp.views.rest import *
如果我进入EC2实例,路径看起来正确; / opt / python / current / app
包含我的应用程序,包括 /opt/python/current/app/myapp/views/rest.py
。
If I ssh into the EC2 instance, the path looks right; /opt/python/current/app
contains my application, including /opt/python/current/app/myapp/views/rest.py
.
我的目录结构包含(当然也有更多):
My directory structure contains (there's more, too, of course):
app/
.ebextensions/
packages.config
python.config
.elasticbeanstalk/
config
optionsettings.myapp-deployment-env
project/
settings.py
application.py
myapp/
views/
rest.py
views.py
__init__.py
在 __ init __。py
我有:
In __init__.py
I've got:
from myapp.views.views import *
from myapp.views.rest import *
该问题不是特定于这些文件 - 如果我添加另一个导入到urls。 py也失败了,所以就像没有找到该应用程序。
The issue is not specific to these files though - if I add another import to urls.py that fails too, so it's like it's not finding the app at all.
packages:
yum:
postgresql-devel: []
在 python.config
我有(试图加载virtualenv,这可能不是必需的?)
In python.config
I've got (in an attempt to load the virtualenv, which might not be necessary?)
container_commands:
00_activate:
command: "source /opt/python/run/venv/bin/activate"
01_make_admin_executable:
command: "chmod +x scripts/createadmin.py"
leader_only: true
02_make_executable:
command: "chmod +rx application.py"
leader_only: true
03_syncdb:
command: "python manage.py syncdb --noinput"
leader_only: true
04_collectstatic:
command: "python manage.py collectstatic --noinput"
option_settings:
- option_name: AWS_SECRET_KEY
value: mykey
- option_name: AWS_ACCESS_KEY_ID
value: myaccesskeyid
- option_name: application_stage
value: "staging"
如果对其他配置文件有帮助,请快乐列出。它们包括设置位置,但没有对PYTHONPATH等的具体引用。
Happy to list the other config files if they're helpful. They do include the settings location but no specific reference to PYTHONPATH etc.
[aws:elasticbeanstalk:application:environment]
DJANGO_SETTINGS_MODULE=project.settings
我已经运行 eb update
和 git aws.push
。
真的很挣扎着这个!我第一次尝试使用AWS部署,显然错过了一些重要的事情。真的感谢帮忙,如果有人知道我错过了什么。
Really struggling with this one! My first attempt at an AWS deployment so have obviously missed something important. Really appreciate the help if anyone knows what I've missed.
推荐答案
原来是一个mod_wsgi vs Django开发服务器问题。 Graham Dumpleton的这篇文章非常有助于理解它(它不能被阅读)。
This turned out to be a mod_wsgi vs Django development server issue. This post by Graham Dumpleton was extremely helpful in understanding it (it can't be skim-read).
mod_wsgi需要被告知我的网站的位置。我的WSGI文件(application.py)现在看起来像这样,导入工作:
mod_wsgi needs to be told of the location of my site. My WSGI file (application.py) now looks like this, and the imports work:
import os
import sys
sys.path.insert(0, '/opt/python/current/app')
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
这篇关于无法在AWS弹性Beanstalk上找到Django App的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!