django simple captcha一直说'CAPTCHA'无效

时间:2013-12-31 06:47:10

标签: python django python-3.x captcha

我按照文档给出的步骤, 首先,它运作良好,但是,我不知道任何错误,它使 invalid Captcha。 我运行manage.py test captcha, 它像这样说:

C:\Windows\system32\cmd.exe /c python.exe manage.py test captcha
Creating test database for alias 'default'...
.......Internal Server Error: /test/
Traceback (most recent call last):
  File "D:\Python33\lib\site-packages\django-1.5.5-py3.3.egg\django\core\handler
s\base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "D:\Python33\lib\site-packages\django_simple_captcha-0.4.1-py3.3.egg\capt
cha\tests\views.py", line 48, in test
    class CaptchaTestForm(forms.Form):
  File "D:\Python33\lib\site-packages\django_simple_captcha-0.4.1-py3.3.egg\capt
cha\tests\views.py", line 51, in CaptchaTestForm
    captcha = CaptchaField(help_text='asdasd')
  File "D:\Python33\lib\site-packages\django_simple_captcha-0.4.1-py3.3.egg\capt
cha\fields.py", line 107, in __init__
    kwargs['widget'] = kwargs.pop('widget', CaptchaTextInput(output_format=kwarg
s.pop('output_format', None)))
  File "D:\Python33\lib\site-packages\django_simple_captcha-0.4.1-py3.3.egg\capt
cha\fields.py", line 73, in __init__
    '%%(%s)s' % key
django.core.exceptions.ImproperlyConfigured: All of %(image)s, %(hidden_field)s,
 %(text_field)s must be present in your CAPTCHA_OUTPUT_FORMAT setting. Could not
 find %(hidden_field)s
Internal Server Error: /test-modelform/
Traceback (most recent call last):
  File "D:\Python33\lib\site-packages\django-1.5.5-py3.3.egg\django\core\handler
s\base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "D:\Python33\lib\site-packages\django_simple_captcha-0.4.1-py3.3.egg\capt
cha\tests\views.py", line 56, in test_model_form
    class CaptchaTestModelForm(forms.ModelForm):
  File "D:\Python33\lib\site-packages\django_simple_captcha-0.4.1-py3.3.egg\capt
cha\tests\views.py", line 59, in CaptchaTestModelForm
    captcha = CaptchaField(help_text='asdasd')
  File "D:\Python33\lib\site-packages\django_simple_captcha-0.4.1-py3.3.egg\capt
cha\fields.py", line 107, in __init__
    kwargs['widget'] = kwargs.pop('widget', CaptchaTextInput(output_format=kwarg
s.pop('output_format', None)))
  File "D:\Python33\lib\site-packages\django_simple_captcha-0.4.1-py3.3.egg\capt
cha\fields.py", line 73, in __init__
    '%%(%s)s' % key
django.core.exceptions.ImproperlyConfigured: All of %(image)s, %(hidden_field)s,
 %(text_field)s must be present in your CAPTCHA_OUTPUT_FORMAT setting. Could not
 find %(hidden_field)s
............

我谷歌一段时间,但没有找到任何结果。 CAPTCHA_OUTPUT_FORMAT可能有问题 和%(hidden_field)s,但我不知道如何解决它?

我对它很无聊。当我在验证码中运行py时,它就是这样说的:

    C:\Windows\system32\cmd.exe /c python.exe fields.py
Traceback (most recent call last):
  File "D:\Python33\Lib\os.py", line 673, in __getitem__
    value = self._data[self.encodekey(key)]
KeyError: 'DJANGO_SETTINGS_MODULE'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Python33\lib\site-packages\django-1.5.5-py3.3.egg\django\conf\__init_
_.py", line 37, in _setup
    settings_module = os.environ[ENVIRONMENT_VARIABLE]
  File "D:\Python33\Lib\os.py", line 676, in __getitem__
    raise KeyError(key)
KeyError: 'DJANGO_SETTINGS_MODULE'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "fields.py", line 1, in <module>
    \ufefffrom captcha.conf import settings
  File "D:\Python33\lib\site-packages\django_simple_captcha-0.4.1-py3.3.egg\capt
cha\conf\settings.py", line 5, in <module>
    CAPTCHA_FONT_PATH = getattr(settings, 'CAPTCHA_FONT_PATH', os.path.normpath(
os.path.join(os.path.dirname(__file__), '..', 'fonts/Vera.ttf')))
  File "D:\Python33\lib\site-packages\django-1.5.5-py3.3.egg\django\conf\__init_
_.py", line 53, in __getattr__
    self._setup(name)
  File "D:\Python33\lib\site-packages\django-1.5.5-py3.3.egg\django\conf\__init_
_.py", line 46, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting CAPTCHA_FONT_PATH
, but settings are not configured. You must either define the environment variab
le DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings
.
shell returned 1

我继续找不到重复的验证码, 有人帮忙吗?

2 个答案:

答案 0 :(得分:0)

请查看以下网址。从第10次谈话开始讨论同样的问题。

https://github.com/mbi/django-simple-captcha/issues/41

上述链接中提供的可能解决方案 -

  • 您是否在全局和虚拟环境中都安装了此库?

    如果是,则卸载不需要的那个。

  • 您是否在设置中重新定义了“CAPTCHA_OUTPUT_FORMAT”?

    如果是,则在评论该行后进行测试。

答案 1 :(得分:0)

这是因为我在我的窗口中删除了全局var = 'DJANGO_SETTINGS_MODULE',我认为这并不是很有用。我在Windows中重置它。 测试最后说OK,这意味着上面的2个警告不是很重要。 但在我修复revalidation in formwizard and single validation in captcha之后,测试显示了很多错误,我ignores。 这个问题让我感到三天或三天以上,为了记住,必须写下来。