我在运行项目时遇到错误:
环境:
请求方法:发布请求URL:http://127.0.0.1:8000/
Django版本:1.8。4 Python版本:2.7。6个已安装的应用程序:('django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','mongo_login')已安装的中间件:('django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware')
回溯:get_响应132中的文件“/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py”。响应=包装的回调(请求,*回调参数,**回调参数)
File "/home/shubham/Documents/python/django project/login/mongo_login/views.py" in register
24. if form.is_valid():
File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py" in
有效吗。回归自我。被束缚而不是自我。错误176中的错误文件“/usr/local/lib/python2.7/dist packages/django/forms/forms.py”。自己full_clean()文件“/usr/local/lib/python2.7/dist packages/django/forms/forms.py”在full_clean 392中。自我_clean_fields()文件“/usr/local/lib/python2.7/dist packages/django/forms/forms.py”,位于_clean_fields 410中。value=getattr(self,'clean_uu%s'%name)()
File "/home/shubham/Documents/python/django project/login/mongo_login/forms.py" in clean_username
56. existing = MongoUser.objects(username=self.cleaned_data['username'])
get 37中的文件“/usr/local/lib/python2.7/dist packages/mongoengine/queryset/manager.py”。queryset=queryset_类(owner,owner._get_collection())文件“/usr/local/lib/python2.7/dist packages/mongoengine/document.py”,位于_get_collection 176中。db=cls_get_db 169中的get_db()文件“/usr/local/lib/python2.7/dist packages/mongoengine/document.py”。在get_db 145中返回get_db(cls._meta.get(“db_别名,默认连接名称”)文件“/usr/local/lib/python2.7/dist packages/mongoengine/CONNECTION.py”。获取连接101中的conn=get\u连接(别名)文件“/usr/local/lib/python2.7/dist-packages/mongoengine/connection.py”。raise ConnectionError(消息)
Exception Type: ConnectionError at /
Exception Value: You have not defined a default connection
代码是:
看法派克
from django.template.context import RequestContext
from django.shortcuts import redirect, render_to_response
from django.conf import settings
from forms import RegistrationForm
from auth import User as MongoUser
def save_user_in_mongo(**kwargs):
new_user = MongoUser.create_user(kwargs['username'], kwargs['password1'], kwargs['email'])
new_user.first_name = kwargs.get('first_name')
new_user.last_name = kwargs.get('last_name')
new_user.save()
return new_user
def register(request, success_url=None, form_class=None,
template_name='registration/registration_form.html',
extra_context=None):
if form_class is None:
form_class = RegistrationForm
if request.method == 'POST':
form = form_class(data=request.POST, files=request.FILES)
if form.is_valid(): # line 24 =======
save_user_in_mongo(**form.cleaned_data)
if success_url is None:
success_url = settings.LOGIN_URL
return redirect(success_url)
else:
form = form_class()
if extra_context is None:
extra_context = {}
context = RequestContext(request)
for key, value in extra_context.items():
context[key] = callable(value) and value() or value
return render_to_response(template_name,
{'form': form},
context_instance=context)
forms.py
from auth import User as MongoUser
from django import forms
from django.utils.translation import ugettext_lazy as _
attrs_dict = {'class': 'required'}
class RegistrationForm(forms.Form):
username = forms.RegexField(regex=r'^[\w.@+-]+$',
max_length=30,
widget=forms.TextInput(attrs=attrs_dict),
label=_("Username"),
error_messages={'invalid': _("This value may contain only letters, numbers and @/./+/-/_ characters.")})
email = forms.EmailField(widget=forms.TextInput(attrs=dict(attrs_dict,
maxlength=75)),
label=_("E-mail"))
password1 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, render_value=False),
label=_("Password"))
password2 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, render_value=False),
label=_("Password (again)"))
first_name = forms.CharField(widget=forms.TextInput(attrs=dict(attrs_dict, maxlength=50)),
label=_("First Name"))
last_name = forms.CharField(widget=forms.TextInput(attrs=dict(attrs_dict, maxlength=50)),
label=_("Last Name"), required=False)
def clean_username(self):
existing = MongoUser.objects(username=self.cleaned_data['username'])#line 56 ======
if existing:
raise forms.ValidationError(_("A user with that username already exists."))
else:
return self.cleaned_data['username']
def clean(self):
if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
if self.cleaned_data['password1'] != self.cleaned_data['password2']:
raise forms.ValidationError(_("The two password fields didn't match."))
return self.cleaned_data
背景派克
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': 'my_database',
'OPTIONS' : {
'socketTimeoutMS' : 500,
}
}
}
我怎样才能解决这个问题?
Django似乎不知道如何连接到数据库。
在设置中定义到DB的默认连接。py
DATABASES = {
'default' : {
'ENGINE' : 'django_mongodb_engine',
'NAME' : 'my_database',
...
'OPTIONS' : {
'socketTimeoutMS' : 500,
...
}
}
}
使用django项目中已添加的sqlite3数据库尝试此操作。
改变你的设置。派克
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'logintest.db',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
我使用jhipster版本7.6.0,这是我的CacheConfiguration类。 以下是redisson的依赖关系: 这是我的应用程序dev.yml: 一切都是由jHipster生成的,在安装redis 3.2.100版后,我遇到了以下异常: 顺便说一下,项目正在成功编译。 提前感谢您的帮助!
问题内容: 我正在尝试将我的应用程序升级到新版本的Firebase。我仔细阅读了设置指南,并编辑了所有代码以匹配新语法。但是,当我运行该应用程序时,出现了这两个错误。 我 在AppDelegate中,并将GoogleServices- Info.plist导入到我的项目中。plist也具有所有正确的信息。其他人遇到这个问题或知道如何解决? 问题答案: 这是您的问题的答案: 要配置Firebase,
如果能够拥有 root权限,可以直接修改 /etc/passwd 文件。找到您 用户ID 起始的行 user:x:1000:112:user,,,:/home/user:/bin/bash 用户登录名 用户口令(通常转储在/etc/shadow文件中) 用户UID 用户GID 用户信息 用户$HOME目录位置 最后一个字段为登录后的默认 Shell, /bin/bash 是程序 bash 的主
创建Spring Boot cloud config应用程序时出现以下错误。有什么帮助吗?
我做了一个叫做“F”的分支,并对Master做了一个结账。当我尝试命令时,我得到了以下消息: 当我尝试时,它给出了以下内容: 我该怎么办?
我有Mysql 8.0.19作为docker实例。在我们之前的应用程序中,我们使用JDK的默认密钥库进行SSL。使用JDK的密钥库连接到Mysql服务器,无论使用SSL还是不使用SSL都可以。这里我们没有手动配置Mysql的SSL。我们使用Mysql的默认SSL机制。 现在出于某种原因,我们决定使用我们自己的密钥库,并使用以下变量覆盖JVM的密钥库 在此之后,与mysql for SSL的连接出现