简体   繁体   English

Django简单验证码-{{form.as_p}}中的错误-'DatabaseWrapper'对象没有属性'Database'

[英]Django Simple Captcha - Error in {{ form.as_p }} - 'DatabaseWrapper' object has no attribute 'Database'

I'm using Django 1.6 with mongoengine. 我在mongoengine上使用Django 1.6。

I just started to try the simple captcha but I have the following error. 我刚刚开始尝试简单的验证码,但出现以下错误。

As it is said in http://django-simple-captcha.readthedocs.org/en/latest/usage.html http://django-simple-captcha.readthedocs.org/en/latest/usage.html中所述

I installed in my env, added to Installed apps, I didn't run syncdb because I work with MongoDB and this is not necessary and finally I added the url(r'^captcha/', include('captcha.urls')), into my url app file. 我安装在env中,添加到已安装的应用程序中,没有运行syncdb,因为我与MongoDB一起工作,这不是必需的,最后我添加了url(r'^ captcha /',include('captcha.urls')) ,放入我的url应用文件中。

My form.py looks like : 我的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()

And my view: 我的看法是:

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,
    })

So when the form is rendered it gaves me this error : 因此,在呈现表单时,它给了我这个错误:

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   

What's wrong with form.as_p ? form.as_p有什么问题? Without this captcha runned fine. 没有这个验证码就可以运行。

You need to run syncdb or migrate or create table captcha_captchastore in some other way, since it is required for simple captcha. 您需要以其他方式运行syncdb或迁移或创建表captcha_captchastore ,因为简单的验证码是必需的。

Edit : I am probably wrong about creating the schema, since you are right about it is not being required. 编辑 :创建模式可能是错误的,因为不需要它是正确的。

But here is an idea. 但这是一个主意。 Mongoddb engine uses djangotoolbox which has class djangotoolbox.db.base.NonrelDatabaseWrapper didn't have that attribute Database until this commit (line marked) So make sure you got the right version. Mongoddb发动机采用djangotoolbox具有类djangotoolbox.db.base.NonrelDatabaseWrapper没有这个属性Database ,直到这个承诺(行标)所以一定要确保你有正确的版本。

Let me know if I am wrong and what the actual solution was. 让我知道我是否做错了,真正的解决方案是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM