我的注册表单在自定义注册表单的密码字段中的form.save()期间引发了ValueError。

以下是异常详细信息(从http://www.pastie.org/1299144复制):

Environment:

Request Method: POST
Request URL: http://192.168.2.206:8080/register/
Django Version: 1.1.1
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
 'django.contrib.admin',
 'django.contrib.contenttypes',
 'django.contrib.markup',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.comments',
 'mysite.registration',
 'mysite.profiles',
 'mysite.epw',
 'mysite.remember_me',
 'mysite.avatar',
 'mysite.django_documents',
 'mysite.inlines',
 'mysite.blog',
 'mysite.forum',
 'tagging']
Installed Middleware:
('django.middleware.cache.UpdateCacheMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.cache.FetchFromCacheMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'mysite.remember_me.views.AutoLogout')


Traceback:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response
  92.                 response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/pymodules/python2.6/django/utils/decorators.py" in _wrapped_view
  48.                 response = view_func(request, *args, **kwargs)
File "/home/karthik/Desktop/EPW_LOCAL/mysite/../mysite/epw/views.py" in register
  1538.             new_user = form.save(request)
File "/home/karthik/Desktop/EPW_LOCAL/mysite/../mysite/epw/form.py" in save
  169.                                                                     profile_callback=profile_callback)
File "/home/karthik/Desktop/EPW_LOCAL/mysite/../mysite/registration/models.py" in create_inactive_user
  110.         registration_profile = self.create_profile(new_user)
File "/home/karthik/Desktop/EPW_LOCAL/mysite/../mysite/registration/models.py" in create_profile
  145.         salt = hashlib.new(str(random.random())).hexdigest()[:5]
File "/usr/lib/python2.6/hashlib.py" in __hash_new
  101.         return __get_builtin_constructor(name)(string)
File "/usr/lib/python2.6/hashlib.py" in __get_builtin_constructor
  80.     raise ValueError, "unsupported hash type"

Exception Type: ValueError at /register/
Exception Value: unsupported hash type


请问谁能解决这个问题。
谢谢

最佳答案

您似乎正在尝试使用它实现自己的注册框架。现有的有什么问题?我认为您通常应该阅读有关Django框架的更多信息,并通读本教程。

查看该回溯,问题出在hashlib.new(str(random.random())).hexdigest()[:5]行中。 (熟悉回溯并弄清问题所在,当您犯错时,您会发现经常需要这样做。)

help(hashlib.new)显示以下内容:

__hash_new(name, string='')
    new(name, string='') - Return a new hashing object using the named algorithm;
    optionally initialized with a string.


“命名算法”应为md5,sha1,sha256等(列表请参见help(hashlib),以及如何使用例如hashlib.md5()代替hashlib.new('md5')。)

关于python - 带有Python 2.6.5和Django框架的“不受支持的哈希类型”错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4183016/

10-12 21:45