【问题标题】:Django Internal Server 500 Error AWS Elastic-Beanstalk issueDjango 内部服务器 500 错误 AWS Elastic-Beanstalk 问题
【发布时间】:2016-10-19 22:58:38
【问题描述】:

如何修复 AWS eb 部署的应用程序上的 Django Internal Server 500 错误?

我是否需要在我的 base.py 文件中更改我允许的主机,以便在 elasticbeanstalk 中拥有 ec2 的 IP 地址?

# SECURITY WARNING: keep the secret key used in production secret!
# Raises ImproperlyConfigured exception if SECRET_KEY not in os.environ
SECRET_KEY = env('SECRET_KEY')

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = (
    'django.contrib.auth',
    'django_admin_bootstrapped',
    'django.contrib.admin',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)

...

STATIC_URL = '/static/'

ALLOWED_HOSTS = []

...

我启用了调试并运行了 eb 配置和 eb 日志。 eb deploy 值显示在下方,eb logs 值显示在下方。如何解决“没有名为 django 的模块”的问题?

    Creating application version archive "app-3e17-161020_112522".
Uploading pronet/app-3e17-161020_112522.zip to S3. This may take a while.
Upload Complete.
INFO: Environment update is starting.                               
INFO: Deploying new version to instance(s).                         
INFO: New application version was deployed to running EC2 instances.
INFO: Environment update completed successfully. 

下面提供的是 eb 日志的输出。

============= i-0b11de8b8521ea5c0 ==============
-------------------------------------
/var/log/httpd/error_log
-------------------------------------
[Thu Oct 20 17:46:59.414032 2016] [:error] [pid 11268] 
[remote 172.31.5.67:41390] Traceback (most recent call last):

[Thu Oct 20 17:46:59.414077 2016] [:error] [pid 11268] 
[remote 172.31.5.67:41390]   File "/opt/python/current/app/pronet/src/pronet/wsgi.py", line 12, in <module>

[Thu Oct 20 17:46:59.414083 2016] [:error] [pid 11268] 
[remote 172.31.5.67:41390]     from django.core.wsgi import get_wsgi_application

[Thu Oct 20 17:46:59.414104 2016] [:error] [pid 11268] 
[remote 172.31.5.67:41390] ImportError: No module named 'django'

[Thu Oct 20 17:47:00.046644 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182] mod_wsgi (pid=11268): Target WSGI script '/opt/python/current/app/pronet/src/pronet/wsgi.py' cannot be loaded as Python module.

[Thu Oct 20 17:47:00.046704 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182] mod_wsgi (pid=11268): Exception occurred processing WSGI script '/opt/python/current/app/pronet/src/pronet/wsgi.py'.

[Thu Oct 20 17:47:00.046738 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182] Traceback (most recent call last):

[Thu Oct 20 17:47:00.046784 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182]   File "/opt/python/current/app/pronet/src/pronet/wsgi.py", line 12, in <module>

[Thu Oct 20 17:47:00.046789 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182]     from django.core.wsgi import get_wsgi_application

[Thu Oct 20 17:47:00.046810 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182] ImportError: No module named 'django'

[Thu Oct 20 17:47:01.340552 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182] mod_wsgi (pid=11268): Target WSGI script '/opt/python/current/app/pronet/src/pronet/wsgi.py' cannot be loaded as Python module.

[Thu Oct 20 17:47:01.340603 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182] mod_wsgi (pid=11268): Exception occurred processing WSGI script '/opt/python/current/app/pronet/src/pronet/wsgi.py'.

[Thu Oct 20 17:47:01.340653 2016] [:error] [pid 11268] [remote 172.31.5.67:43182] Traceback (most recent call last):

[Thu Oct 20 17:47:01.340701 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182]   File "/opt/python/current/app/pronet/src/pronet/wsgi.py", line 12, in <module>

[Thu Oct 20 17:47:01.340706 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182]     from django.core.wsgi import get_wsgi_application

[Thu Oct 20 17:47:01.340728 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182] ImportError: No module named 'django'

链接到 github 项目。您可以在这里查看所有代码

https://github.com/IantheFlyingHawaiian/Pronet

【问题讨论】:

  • 您是否在settings.py 中启用了调试功能?如果是这样,那里的追溯是什么?
  • 启用DEBUG 在控制台查看错误
  • 我启用了调试,但我仍然收到相同的“django module not found error”。任何想法为什么?

标签: python django amazon-web-services internal-server-error http-status-code-500


【解决方案1】:

这是你做的吗?

pip freeze > requirements.txt

如果您不这样做,AWS 将不知道它应该install Django and other dependencies on your EC2 instances for your deployment。

【讨论】:

    【解决方案2】:

    在我的情况下 sqllite 出现错误

    从 settings.py 中删除数据库设置并尝试部署

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        }
    }
    

    然后我配置了 AWS RDS。

    【讨论】:

    • 我也是这样。操作系统 sqlite 版本对于我使用的适配器来说太低了..
    猜你喜欢
    • 2020-02-20
    • 2016-03-07
    • 1970-01-01
    • 2014-03-25
    • 2021-09-22
    • 2019-11-27
    • 1970-01-01
    • 2018-11-01
    • 2015-06-25
    相关资源
    最近更新 更多