首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >django简单captcha一直说“无效的captcha”

django简单captcha一直说“无效的captcha”
EN

Stack Overflow用户
提问于 2013-12-31 06:47:09
回答 2查看 1.3K关注 0票数 0

我遵循了docs给出的步骤,首先,它工作得很好,但是,我不知道有什么不对的地方,它制造了一个invalid Captcha。我运行manage.py test captcha,它是这样写的:

代码语言:javascript
复制
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可能有问题,但我不知道如何解决?

当我在captcha上运行一个py时,我对它感到厌烦,它说:

代码语言:javascript
复制
    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

在那里我继续找不到复制的卡普查,有什么帮助吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-31 10:54:29

请查阅以下网址。从第十次对话中,我们讨论了同样的问题。

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

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

  • 您是否在全局环境和虚拟环境中都安装了这个库? 如果是,则卸载不需要的。
  • 您在设置中重新定义了"CAPTCHA_OUTPUT_FORMAT“吗? 如果是,那么在注释该行之后进行测试。
票数 0
EN

Stack Overflow用户

发布于 2014-01-02 14:42:54

这是因为我已经删除了窗口中的globle var='DJANGO_SETTINGS_MODULE',我认为这并没有多大用处。我把它重新设置在窗户上。测试最后说到了OK,这意味着上面的两个警告并不重要。但是在我修复了revalidation in formwizard and single validation in captcha之后,测试就会显示出大量的错误,并且我会修改它。这个问题使我烦恼了三天或更长时间,为了记住,我不得不写上这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20853114

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档