Django+;赫罗库+;MongoDB Atlas(Djongo)=数据库错误,无异常 问题的一行描述
每当部署在heroku上的django应用程序试图访问我的MongoDB Atlas集群以提交表单或检查管理员登录时,它都会抛出类似附加错误的内容 额外细节 heroku构建上可重复的错误 我认为这个错误与heroku如何与我的MongoDB Atlas集群交互有关,因为当我在本地运行构建时,我能够让应用程序成功读取并修改数据库中的不同记录 我已经启用了从所有IP地址到Atlas群集的通信,从我的Heroku应用程序和配置变量中删除了默认的Heroku PostrgreSQL数据库,并将我自己的数据库IP存储为配置变量 任何帮助都将不胜感激 Python脚本Django+;赫罗库+;MongoDB Atlas(Djongo)=数据库错误,无异常 问题的一行描述,django,mongodb,heroku,nosql,djongo,Django,Mongodb,Heroku,Nosql,Djongo,每当部署在heroku上的django应用程序试图访问我的MongoDB Atlas集群以提交表单或检查管理员登录时,它都会抛出类似附加错误的内容 额外细节 heroku构建上可重复的错误 我认为这个错误与heroku如何与我的MongoDB Atlas集群交互有关,因为当我在本地运行构建时,我能够让应用程序成功读取并修改数据库中的不同记录 我已经启用了从所有IP地址到Atlas群集的通信,从我的Heroku应用程序和配置变量中删除了默认的Heroku PostrgreSQL数据库,并将我自己的
#模型脚本
从django.db导入模型
类请求(models.Model):
content=models.CharField(最大长度=130)
标识符=models.CharField(最大长度=30)
#视图脚本
从django.shortcuts导入渲染
从django.shortcuts导入重定向
从django.url反向导入
从django.http导入HttpResponse
从django.views.generic导入CreateView
from.models导入请求
#在这里创建您的视图。
def索引(请求):
返回HttpResponse(“euler calc终端GUI”)
def马铃薯(请求):
返回HttpResponse(“土豆”)
类请求视图(CreateView):
model=RawRequest
字段=('content','identifier')
def get_success_url(自我):
返回反向(“马铃薯”)
"""
eulercalc项目的Django设置。
由使用django 3.0.5的“django admin startproject”生成。
有关此文件的详细信息,请参阅
https://docs.djangoproject.com/en/3.0/topics/settings/
有关设置及其值的完整列表,请参见
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
导入操作系统
进口django_heroku
#在项目内部构建如下路径:os.path.join(BASE_DIR,…)
BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(u文件_u)))
#快速启动开发设置-不适合生产
#看https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
#安全警告:请对生产中使用的密钥保密!
秘密密钥=#一个秘密
#安全警告:不要在生产环境中打开调试的情况下运行!
调试=真
允许的_主机=[]
#应用程序定义
已安装的应用程序=[
“django.contrib.admin”,
“django.contrib.auth”,
“django.contrib.contenttypes”,
“django.contrib.sessions”,
“django.contrib.messages”,
“django.contrib.staticfiles”,
“脆皮形式”,
"终点站",,
]
CRISPY_模板_包='bootstrap4'
中间件=[
'django.middleware.security.SecurityMiddleware',
“django.contrib.sessions.middleware.SessionMiddleware”,
'django.middleware.common.CommonMiddleware',
“django.middleware.csrf.CsrfViewMiddleware”,
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.xFrameOptions中间件',
]
ROOT_URLCONF='eulercalc.url'
模板=[
{
'BACKEND':'django.template.backends.django.DjangoTemplates',
“DIRS”:[],
“应用程序目录”:正确,
“选项”:{
“上下文处理器”:[
“django.template.context_processors.debug”,
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_应用程序='eulercalc.WSGI.APPLICATION'
#数据库
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
数据库={
“默认值”:{
“引擎”:“djongo”,
“名称”:“euler calc”,
“客户”:{
'host':str(os.environ.get('MONGODB_URL'),
“授权机制”:“紧急停堆-SHA-1”
}
}
}
#密码验证
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-密码验证器
验证密码验证程序=[
{
'NAME':'django.contrib.auth.password\u validation.UserAttributesMilarityValidator',
},
{
'NAME':'django.contrib.auth.password\u validation.MinimumLengthValidator',
},
{
'NAME':'django.contrib.auth.password\u validation.CommonPasswordValidator',
},
{
'NAME':'django.contrib.auth.password\u validation.NumericPasswordValidator',
},
]
#国际化
# https://docs.djangoproject.com/en/3.0/topics/i18n/
语言代码='en us'
时区='UTC'
使用_I18N=True
使用\u L10N=True
使用_TZ=True
#静态文件(CSS、JavaScript、图像)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
静态URL='/STATIC/'
#激活Django Heroku。
django_heroku.settings(locals())
回溯
事实证明,我忘记将sqlparse添加到requirements.txt中,因此,heroku无法将Djongo的SQL解析运行到noSQL中。基于此,0.2.4版似乎是最稳定的版本 requirements.txt
Environment:
Request Method: POST
Request URL: https://euler-calc.herokuapp.com/
Django Version: 2.2.12
Python Version: 3.6.10
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'terminal']
Installed Middleware:
('whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/app/.heroku/python/lib/python3.6/site-packages/djongo/sql2mongo/query.py" in parse
842. return handler(self, statement)
File "/app/.heroku/python/lib/python3.6/site-packages/djongo/sql2mongo/query.py" in _insert
907. query = InsertQuery(self, self.db, self.connection_properties, sm, self._params)
File "/app/.heroku/python/lib/python3.6/site-packages/djongo/sql2mongo/query.py" in __init__
339. super().__init__(*args)
File "/app/.heroku/python/lib/python3.6/site-packages/djongo/sql2mongo/query.py" in __init__
61. self.parse()
File "/app/.heroku/python/lib/python3.6/site-packages/djongo/sql2mongo/query.py" in parse
409. self._fill_values(statement)
File "/app/.heroku/python/lib/python3.6/site-packages/djongo/sql2mongo/query.py" in _fill_values
367. raise SQLDecodeError
The above exception () was the direct cause of the following exception:
File "/app/.heroku/python/lib/python3.6/site-packages/djongo/cursor.py" in execute
56. params)
File "/app/.heroku/python/lib/python3.6/site-packages/djongo/sql2mongo/query.py" in __init__
769. self._query = self.parse()
File "/app/.heroku/python/lib/python3.6/site-packages/djongo/sql2mongo/query.py" in parse
864. raise exe from e
The above exception (FAILED SQL: INSERT INTO "terminal_rawrequest" ("content", "identifier") VALUES (%(0)s, %(1)s)
Params: ['2 + 2', 'heroku']
Version: 1.3.2) was the direct cause of the following exception:
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
84. return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/djongo/cursor.py" in execute
59. raise db_exe from e
The above exception () was the direct cause of the following exception:
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/base.py" in view
71. return self.dispatch(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/base.py" in dispatch
97. return handler(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/edit.py" in post
172. return super().post(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/edit.py" in post
142. return self.form_valid(form)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/edit.py" in form_valid
125. self.object = form.save()
File "/app/.heroku/python/lib/python3.6/site-packages/django/forms/models.py" in save
458. self.instance.save()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py" in save
741. force_update=force_update, update_fields=update_fields)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py" in save_base
779. force_update, using, update_fields,
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py" in _save_table
870. result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py" in _do_insert
908. using=using, raw=raw)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/manager.py" in manager_method
82. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in _insert
1186. return query.get_compiler(using=using).execute_sql(return_id)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
1375. cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
99. return super().execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
67. return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute_with_wrappers
76. return executor(sql, params, many, context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
84. return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py" in __exit__
89. raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
84. return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/djongo/cursor.py" in execute
59. raise db_exe from e
Exception Type: DatabaseError at /
Exception Value:
django==2.2.12
djongo==1.3.2
gunicorn==19.9.0
django-heroku==0.3.1
django-crispy-forms==1.9.0
dnspython==1.16.0
sqlparse==0.2.4