Django - django-simple-captcha的问题
我在使用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}),
)
3 个回答
-1
在Windows操作系统中
首先,打开命令行工具,输入
pip install captcha
来安装验证码的库。接着,找到你安装的应用程序的设置文件 setting.py,里面要添加 'captcha' 这个内容。
然后,去 urls.py 文件里添加一个网址链接。
url(r'^captcha/', include('captcha.urls'))
在 forms.py 文件中写一些代码。
from captcha.fields import CaptchaField captcha = CaptchaField()
最后,提交你的修改,并且更改 captcha 的 .html 文件。
<button class='js-captcha-refresh'>Refresh Captcha</button><br><br> <input type="submit" class="btn btn-default" value="Submit" />
0
信息不多,但我们可以试试。如果你用的是谷歌浏览器,可以按下Ctrl和Shift键再加上I键,这样就能打开浏览器的检查工具。然后找到“资源”这个标签,那里应该会有关于图片资源的错误信息。查看一下它尝试加载的那个网址,看看为什么在那个网址上找不到图片。
6
确保你已经安装了Captcha应用所需的所有依赖项:先进入你的项目文件夹,然后运行:
./manage.py test captcha
看看有没有报错信息。
另外,确保你已经完成了安装说明中的四个步骤:http://code.google.com/p/django-simple-captcha/#Installation