【问题标题】:django simple captcha keeps saying `invalid CAPTCHA`django simple captcha 一直说“无效的验证码”
【发布时间】:2014-01-18 03:21:29
【问题描述】:

我已按照文档给出的步骤进行操作, 首先,它运作良好,但是,我不知道有什么问题,它使 一个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
............

我google了一会儿,但没有找到任何结果。 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

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

【问题讨论】:

    标签: python django python-3.x captcha


    【解决方案1】:

    这是因为我在我的 windows 中删除了 globle var='DJANGO_SETTINGS_MODULE',我认为这没什么用处。我在Windows中重置它。 并且测试最后说OK,这意味着上面的2个警告不是很重要。 但是在我修复了revalidation in formwizard and single validation in captcha 之后,测试显示了很多错误,我ignoresit。 这个问题困扰了我三天或更长时间,必须写下来记住。

    【讨论】:

      【解决方案2】:

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

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

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

      • 您是否也在全局和虚拟环境中安装了这个库?

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-19
        • 1970-01-01
        • 2011-11-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-22
        相关资源
        最近更新 更多