为什么Djangosimplemathcaptcha不提出问题?

2024-04-25 18:04:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在我的项目中集成Django简单数学验证码,但是表单没有呈现问题。我已经完成了文档中的所有步骤,并呈现了表单:

{% for field in form %}
  {{ field.label_tag }}
  {{ field }}
  {% if field.errors %}
      {{ field.errors }}
  {% else %}
  {% endif %}
  {% endfor %}

我得到验证码标签,即验证码:

以及验证码应答输入

所有验证码错误消息

但毫无疑问。我做错了什么?你知道吗


Tags: 项目djangoin文档form表单fieldfor
1条回答
网友
1楼 · 发布于 2024-04-25 18:04:00

我在Django 2.0+上尝试了这个包,但是验证码问题没有被呈现出来。以下是从视图打印表单时的输出:

System check identified no issues (0 silenced).
September 28, 2018 - 05:52:00
Django version 2.0.8, using settings 'stackover.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
<input type="text" name="captcha_0" size="5" required id="id_captcha_0" />
<input type="hidden" name="captcha_1" value="2b05507f9541c630c35d55509b05deea6e04e8cc" required id="id_captcha_1" />
[28/Sep/2018 05:52:03] "GET / HTTP/1.1" 200 118

如果您仔细查看这个包的源代码,您将看到问题被呈现为一个html类captcha-question,这在上面的html输出中是不存在的。然而,在将Django降级到1.8版本之后,我的模板中的{{ form }}呈现了下面所示的所有三个字段,即问题、输入和隐藏的散列答案。因此,如果您使用的是Django 2.0+,那么您需要降级才能使用此软件包,或者您必须调整此软件包以与当前版本兼容(我想这将是一些工作!)。以下是我在视图中打印验证码表单时得到的简单输出:

Django version 1.8, using settings 'stackover.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

<tr><th><label for="id_captcha_0">Captcha:</label></th>
<td><span class="captcha-question">What is the result of 1 - 1?</span>
<input id="id_captcha_0" name="captcha_0" size="5" type="text" />
<input id="id_captcha_1" name="captcha_1" type="hidden" value="aad5d3b0165de882bc40cfbfa47f8262d6d8f9da" /></td></tr>
[28/Sep/2018 06:19:03]"GET / HTTP/1.1" 200 425

相关问题 更多 >