1

我将 Django 1.6 与 mongoengine 一起使用。

我刚开始尝试简单的验证码,但出现以下错误。

正如在http://django-simple-captcha.readthedocs.org/en/latest/usage.html中所说

我安装在我的环境中,添加到已安装的应用程序中,我没有运行 syncdb,因为我使用 MongoDB,这不是必需的,最后我添加了 url(r'^captcha/', include('captcha.urls')) ,进入我的 url 应用程序文件。

我的 form.py 看起来像:

from django import forms
from captcha.fields import CaptchaField

class PostForm(forms.Form):
    user = forms.CharField(max_length=256)
    password = forms.CharField(widget=forms.PasswordInput)
    email = forms.CharField(max_length=256)
    captcha = CaptchaField()

而我的观点:

def post_form_upload(request):
    if request.method == 'GET':
        form = PostForm()
    else:
        # A POST request: Handle Form Upload
        form = PostForm(request.POST) # Bind data from request.POST into a PostForm

        # If data is valid, proceeds to create a new post and redirect the user
        if form.is_valid():
            user = form.cleaned_data['user']
            password = form.cleaned_data['password']
            email = form.cleaned_data['email']
            connect('reborn')
            User.create_user(user,password,email)
            #return HttpResponse("Usuari nou creat")
            return render(request, 'game/welcomeuser.html', {
                'user': user,
            })
    return render(request, 'game/post_form_upload.html', {
        'form': form,
    })

因此,当呈现表单时,它给了我这个错误:

AttributeError at /game/form_upload.html
'DatabaseWrapper' object has no attribute 'Database'

In template /.../post_form_upload.html, error at line 2
'DatabaseWrapper' object has no attribute 'Database'
1   <form action='/game/form_upload.html' method='post'>{% csrf_token %}
2   {{ form.as_p }} <- HERE
3   <input type='submit' value='Submit' />
4   </form>
5   

form.as_p 有什么问题?没有这个验证码运行良好。

4

1 回答 1

0

您需要以captcha_captchastore其他方式运行 syncdb 或迁移或创建表,因为它是简单验证码所必需的。

编辑:关于创建模式我可能错了,因为你是对的,不需要它。

但这里有一个想法。Mongoddb 引擎使用djangotoolbox,它的类在此提交djangotoolbox.db.base.NonrelDatabaseWrapper之前没有该属性(标记行)因此请确保您获得了正确的版本。Database

让我知道我是否错了以及实际的解决方案是什么。

于 2014-04-29T11:08:05.350 回答