我对http://code.google.com/p/django-simple-captcha/项目有疑问。我按照程序安装验证码,表格有效但浏览器不加载图片。 怎么办?
我的模式:
from django.conf.urls.defaults import patterns, include, url
from django.conf import settings
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', 'main.views.main', name="main_page"),
url(r'^registration$', 'main.views.registration', name="registration"),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
# Captcha
url(r'^captcha/', include('captcha.urls')),
)
if settings.DEBUG:
urlpatterns += patterns('',
(r'^files/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
)
答案 0 :(得分:6)
确保您拥有Captcha应用程序的所有依赖项:cd进入项目目录,然后运行:
./manage.py test captcha
查看是否报告任何错误。
另外,请确保您已完成安装说明中的四个步骤:http://code.google.com/p/django-simple-captcha/#Installation
答案 1 :(得分:0)
这不是很多信息,但我们走了。如果您有谷歌浏览器,您可以执行ctrl-shift-i打开浏览器检查器。转到资源选项卡,它应该有关于图像资源的错误。检查它尝试加载的网址,并查看该网址上没有图片的原因。
答案 2 :(得分:0)
pip install captcha
在已安装的应用中编辑setting.py以提及&#39; captcha&#39;
之后将URL添加到urls.py,
url(r'^captcha/', include('captcha.urls'))
forms.py写
from captcha.fields import CaptchaField
captcha = CaptchaField()
提交并更改验证码.html文件
<button class='js-captcha-refresh'>Refresh Captcha</button><br><br>
<input type="submit" class="btn btn-default" value="Submit" />