简体   繁体   中英

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

I'm using Django 1.6 with mongoengine.

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

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.

My form.py looks like :

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 ? 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.

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.

Let me know if I am wrong and what the actual solution was.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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