注册用户时 django-registration 中出现 NotImplementedError

2024-04-19

我有一个 django 应用程序并尝试使用django-registration应用程序在其中。下面是我的设置和代码

设置.py

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'south',
    'registration',
    'user_profile',
 )

AUTH_PROFILE_MODULE = "user_profile.UserProfile"
AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
)

project urls.py file

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/', include('user_profile.urls')),
    url(r'^accounts/', include('registration.backends.default.urls')),
 )

用户个人资料 urls.py file

from registration.views import RegistrationView

urlpatterns = patterns('',
    url(r'^register/$', RegistrationView.as_view(),
        {'backend': 'user_profile.backends.RegistrationBackend'},
        name='registration_register'),
)

user_profile.backends.py file

from .forms import RegistrationForm
from user_profile.models import UserProfile
from registration.views import RegistrationView

class RegistrationBackend(RegistrationView):
    def get_form_class(self, request)
        return RegistrationForm

    def register(self, request, **kwargs):
        kwargs["username"] = kwargs["email"]
        user = super(RegistrationBackend, self).register(request, **kwargs)
        UserProfile.objects.create(user=user)
        return user

从上面的代码来看,当用户点击 url 时localhost:8000/accounts/register将显示一个注册表,输入所有字段后(username,email, password, password)并点击register按钮我得到以下内容NotImplementedError

NotImplementedError at /accounts/register/
No exception supplied
Request Method: POST
Request URL:    http://localhost:8000/accounts/register/
Django Version: 1.5.1
Exception Type: NotImplementedError

追溯

Traceback:
File "/home/user/proj/combined/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  115.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/registration/views.py" in dispatch
  79.         return super(RegistrationView, self).dispatch(request, *args, **kwargs)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
  86.         return handler(request, *args, **kwargs)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/registration/views.py" in post
  35.             return self.form_valid(request, form)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/registration/views.py" in form_valid
  82.         new_user = self.register(request, **form.cleaned_data)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/registration/views.py" in register
  109.         raise NotImplementedError

Exception Type: NotImplementedError at /accounts/register/
Exception Value: 

谁能知道如何避免这种情况NotImplementedError,实际上按照原来的观点python2.7/site-packages/registration/views.py , the register方法是

def register(self, request, **cleaned_data):
    """
    Implement user-registration logic here. Access to both the
    request and the full cleaned_data of the registration form is
    available here.

    """
    raise NotImplementedError

但我提供了后端类,用于将我的 url 中的用户注册为 {'backend': 'user_profile.backends.RegistrationBackend'},但它仍然没有覆盖并显示原始功能错误。

那么我在上述情况下做错了什么以及如何修复并让用户保存?

Edit

修改代码后,如所示Paco

当尝试注册用户时,我收到以下错误

error at /accounts/register/
[Errno 111] Connection refused
Request Method: POST
Request URL:    http://localhost:8000/accounts/register/
Django Version: 1.5.1
Exception Type: error
Exception Value:    
[Errno 111] Connection refused

追溯

Traceback:
File "/home/user/proj/combined/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  115.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/registration/views.py" in dispatch
  79.         return super(RegistrationView, self).dispatch(request, *args, **kwargs)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
  86.         return handler(request, *args, **kwargs)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/registration/views.py" in post
  35.             return self.form_valid(request, form)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/registration/views.py" in form_valid
  82.         new_user = self.register(request, **form.cleaned_data)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/registration/backends/default/views.py" in register
  80.                                                                     password, site)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/django/db/transaction.py" in inner
  223.                 return func(*args, **kwargs)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/registration/models.py" in create_inactive_user
  91.             registration_profile.send_activation_email(site)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/registration/models.py" in send_activation_email
  270.         self.user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
File "/home/user/proj/combined/local/lib/python2.7/site-packages/django/contrib/auth/models.py" in email_user
  422.         send_mail(subject, message, from_email, [self.email])
File "/home/user/proj/combined/local/lib/python2.7/site-packages/django/core/mail/__init__.py" in send_mail
  62.                         connection=connection).send()
File "/home/user/proj/combined/local/lib/python2.7/site-packages/django/core/mail/message.py" in send
  255.         return self.get_connection(fail_silently).send_messages([self])
File "/home/user/proj/combined/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py" in send_messages
  88.             new_conn_created = self.open()
File "/home/user/proj/combined/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py" in open
  49.                                            local_hostname=DNS_NAME.get_fqdn())
File "/usr/lib/python2.7/smtplib.py" in __init__
  249.             (code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py" in connect
  309.         self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py" in _get_socket
  284.         return socket.create_connection((port, host), timeout)
File "/usr/lib/python2.7/socket.py" in create_connection
  571.         raise err

Exception Type: error at /accounts/register/
Exception Value: [Errno 111] Connection refused

我的类似问题解决了

from registration.backends.model_activation.views import RegistrationView

代替

from registration.views import RegistrationView

in urls.py(Django 1.9)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

注册用户时 django-registration 中出现 NotImplementedError 的相关文章

  • 不要在异常堆栈中显示 Python raise-line

    当我在 Python 库中引发自己的异常时 异常堆栈将引发行本身显示为堆栈的最后一项 这显然不是一个错误 在概念上是正确的 但是当您在外部使用代码 例如作为模块 时 它会将重点放在对调试无用的东西上 有没有办法避免这种情况并强制 Pytho
  • 使用 Python 连接从 FTP 检索文件

    我构建了这个简单的工具来暴力破解并连接到 ftp 服务器 import socket import ftplib from ftplib import FTP port 21 ip 192 168 1 108 file1 passwords
  • 没有操作的 HTML 表单

    在 Django Pinax 中 我遇到过这样的登录表单
  • Python 3:如何更改GDAL中的图像数据?

    我有一个 GeoTIFF 图像 其中包含颜色表和带有 8 位表键的单个栅格带 并且使用 LZW 压缩 我加载该图像gdal Open https gdal org python osgeo gdal module html 我还有一个包含
  • 如何在Python中通过URL下载Azure Blob存储文件?

    我正在尝试从我的存储帐户下载 Azure Blob 存储文件 为此 我检查了 URL 是什么 并且正在执行以下操作 with urllib request urlopen
  • 为什么我在 Python 中收到“连接被拒绝”错误? (插座)

    我是套接字新手 请原谅我完全缺乏理解 我有一个服务器脚本 server py usr bin python import socket import the socket module s socket socket Create a so
  • Matplotlib 动画未显示

    当我在家里的电脑上尝试这个时 它可以工作 但在工作的电脑上却不行 这是代码 import numpy as np import matplotlib pyplot as plt import matplotlib animation as
  • scipy 的 curve_fit 函数的尺寸问题

    我对 python 中的曲线拟合以及一般的 python 都很陌生 目前 我正在尝试使用 scipy 中的 curve fit 模块来拟合 4 个光谱峰 简而言之 我的文本文件中有两列数据 所以我的第一步是将数据导入到两个数组中 一个包含
  • Python lmfit:拟合 2D 模型

    我正在尝试将二维高斯拟合到一些灰度图像数据 该数据由一个二维数组给出 lmfit 库实现了一个易于使用的模型类 它应该能够做到这一点 不幸的是文档 http lmfit github io lmfit py model html http
  • 使用底图和Python在地图中绘制海洋

    我正在绘制此处提供的 netCDF 文件 https goo gl QyUI4J https goo gl QyUI4J Using the code below the map looks like this 然而 我希望海洋是白色的 更
  • OpenCV 在使用 anaconda 的 Linux 上无法与 python 正常工作。收到 cv2.imshow() 未实现的错误

    这就是我得到的确切错误 我的操作系统是 Ubuntu 16 10 OpenCV 错误 未指定错误 该功能未实现 使用 Windows GTK 2 x 或 Carbon 支持重新构建库 如果您使用的是 Ubuntu 或 Debian 请安装
  • 在 Django 1.9 中使用信号

    在 Django 1 8 中 我能够使用信号执行以下操作 一切顺利 init py from signals import 信号 py receiver pre save sender Comment def process hashtag
  • 使用 pymongo 查询空字段

    我想使用 python 查询 mongo 中的空字段 但是它很难处理单词 null 或 false 它要么给我错误 它们在 python 中未定义 要么在 mongo 中搜索字符串 null 和 false 这两种情况我都不希望发生 col
  • python中不规则点之间的坐标列表

    想象一下 我们为 x 和 y 随机选择两个介于 0 到 100 之间的点 例如 95 7 35 6 现在使用简单的 pygame draw line 函数 我们可以轻松地在这些点之间绘制一条没有任何间隙的线 我的问题是 我们如何找到两点之间
  • 来自字典列表列表的 Pandas DataFrame

    我有一个数据结构 它是字典列表的列表 Height 86 Left 1385 Top 215 Width 86 Height 87 Left 865 Top 266 Width 87 Height 103 Left 271 Top 506
  • 当请求太大时,Nginx(我认为)会以错误的权限保存文件

    所以 我对托管和 Linux 等都是完全陌生的 所以如果我说错了 请原谅我 我还在学习 我正在使用 Django 创建一个小型个人网站 我想把它放到网上看看是否一切正常 我从 linode 买了一台便宜的服务器 并使用 Digital Oc
  • Python 中的“lambda”是什么意思,最简单的使用方法是什么?

    您能否给出一个示例和其他示例来说明何时以及何时不使用 Lambda 我的书给了我一些例子 但它们很令人困惑 拉姆达 起源于拉姆达演算 http en wikipedia org wiki Lambda calculus和 AFAIK 首先实
  • 如何加速Python循环

    我查看了几个网站上的一些讨论 但没有一个给我解决方案 这段代码运行时间超过5秒 for i in xrange 100000000 pass 我正在研究整数优化问题 我必须使用O n log n 算法编辑 O n 4 算法 其中n代表矩阵的
  • 交响二阶颂歌

    我有一个简单的二阶 ODE 的齐次解 当我尝试使用 Sympy 求解初始值时 它返回相同的解 它应该替代 y 0 和 y 0 并产生一个没有常数的解 但事实并非如此 这是建立方程的代码 它是一个弹簧平衡方程 k 弹簧常数 m 质量 我在其他
  • 预提交钩子 git 错误

    我正在尝试在 python 中执行预提交 git hook 以检查文件的行长度是否小于 80 个字符 但是我收到没有此类文件 目录的错误 我在 fedora 上并设置了 usr bin python help 将不胜感激 usr bin e

随机推荐

  • 从 Visual C++ 调用 C# 代码

    基本上我需要从 Visual C 代码调用 C 代码 在阅读了大量有关可能方法的文章后 我决定使用 C CLI 机制 最初我决定在 C 本机代码 dll 库项目 中使用一些函数 它们将调用 CLR 项目中的一些函数 CLR 项目将调用 C
  • 为什么我们不能在 while 循环中定义变量?

    我们可以做的 using Stream s and for int i 为什么我们不能也做这样的事情 while int i NextNum gt 0 我发现它非常有用且明智 我不是语言设计师 但我会给出一个有根据的猜测 里面的子句whil
  • jQuery DatePicker 未加载

    我有一段 jQuery 由于某种原因根本无法加载 我想知道这是否是我的语法错误 或者我是否遗漏了一些对其工作至关重要的东西 这被放置在包含的页面上 div class demo p Date p div
  • Unity3D 与 UIView 集成

    如果这个问题重复 请纠正我 我刚刚接触到Unity3D 我只是想问是否可以将Unity3D集成到其他UIView之上 我认为这是不可能的 因为生成的 AppController mm 充当UIApplicationDelegate 即使你设
  • 如何将字符串转换为整数或浮点数

    我有一个文本字段 用户可以在其中输入数字 并且我希望能够根据用户输入将字符串转换为整数或浮点数 在 Ruby 中是否有一种简单的方法可以做到这一点 例如 User Input 123 gt Output 123 User Input 123
  • 在 MAMP 中使用 Laravel 设置 PostgreSQL

    我在我的 MAC 上使用 MAMP 因为它默认带有 MySQL 但现在我需要在我的一个项目中使用 PostgreSQL 如何在 Laravel 项目的 MAMP 中设置 postgreSQL 好吧 如果你决定使用 MAMP 附带的 post
  • Web应用的细粒度授权

    我有一个 C net 应用程序 为公司的内部用户和外部客户提供服务 我需要进行细粒度的授权 比如谁访问什么资源 因此 我需要基于资源或基于属性的授权 而不是基于角色的授权 我想到的是 为我的 net 应用程序实现我自己的授权机制和 SQL
  • 具有多列的 ORMLITE ORDER_BY

    我在用ormlite在我最近的android项目中 我想对表中多列 比如两列 的查询进行排序 我怎样才能做到这一点 这是单个订单的代码 QueryBuilder
  • 如何阻止 UIScrollView 水平弹跳?

    我有一个 UIScrollView 显示垂直数据 但水平部分不比 iPhone 的屏幕宽 问题是用户仍然可以水平拖动 并且基本上暴露了 UI 的空白部分 我尝试过设置 scrollView alwaysBounceHorizontal NO
  • 如何在设计时避免 XAML 代码中出现“对象引用未设置到对象实例”异常?

    我对我自己设计的 wpf 用户控件有问题 问题是我得到了object reference not set to an instance of an object当我在程序中实现用户控件时 设计时 XAML 代码中出现异常 设计师向我展示了以
  • Teradata:数据透视中的 IN 子句无法从表中获取数据

    我想提取一些Calender Weeks从年度数据来看 完成后 我想旋转它 以便每个都有一行ID 我们有一张桌子DB MY CWs只有一列CW含有Calender Weeks我们感兴趣 以下代码提取相关内容Calender Weeks CR
  • 文件系统树“任意深度的子文件夹”的 Get-ChildItem 通配符

    我想获取特定子文件夹内特定扩展名的所有文件 但可以位于文件系统内的任何级别 例如 Get ChildItem Source Release nupkg recurse 简单的星号可以工作 但会在 源 下的直接级别上进行搜索 但不会在树中进行
  • 使用 linq 加载除另一个集合之外的集合

    我有这样的搜索方法 public List
  • 为什么 GridBagLayout 将我的组件居中而不是放在角落?

    到目前为止 我设法避免使用GridBagLayout 手工代码 尽可能多 但这次我无法避免它 我正在阅读SUN的教程网格包布局 http download oracle com javase tutorial uiswing layout
  • Webpack stats.json 文件为空

    当我运行以下命令时 我得到一个空的 stats json 文件 webpack env production profile json output filename stats json 我发现 由于我在开发和生产环境中使用不同的 Web
  • AngularJS:列出所有表单错误

    背景 我目前正在开发一个带有选项卡的应用程序 我想列出验证失败的字段 部分 以引导用户在右侧选项卡中查找错误 所以我尝试利用form error这样做 但我还没有完全让它发挥作用 如果验证错误发生在ng repeat e g div div
  • PrimeFaces 7.0

    在 PrimeFaces 8 中 似乎可以在使用时启用 禁用 HMTML sanitizer
  • git pre-status 或 post-status hook

    我想运行 lintergit status 不过似乎没有pre status nor post status hook 如何给 git 添加一个 hook The 精美文档 https git scm com book en v2 Cust
  • 微服务之间的通信

    假设您有微服务 A B 和 C 它们当前都通过 HTTP 进行通信 假设服务 A 向服务 B 发送请求 服务 B 得到响应 然后 该响应中返回的数据必须发送到服务 C 进行一些处理 然后最终返回到服务 A 服务 A 现在可以在网页上显示结果
  • 注册用户时 django-registration 中出现 NotImplementedError

    我有一个 django 应用程序并尝试使用django registration应用程序在其中 下面是我的设置和代码 设置 py INSTALLED APPS django contrib auth django contrib conte