1

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.

1 Answers1

0

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.

lehins
  • 9,642
  • 2
  • 35
  • 49
  • Thanks, do u know where I can find the structure of this table ? thanks. – user3584455 Apr 29 '14 at 11:20
  • Sorry I don't have much experience with mongoDB, is that what you're looking for: https://github.com/mbi/django-simple-captcha/blob/master/captcha/models.py#L36 – lehins Apr 29 '14 at 11:26
  • I think I got it. Do this: from djangotoolbox.db.base import NonrelDatabaseWrapper hasattr(NonrelDatabaseWrapper, 'Database') if you got False you got an old version of djangotoolbox here is the commit that fixed it: https://github.com/django-nonrel/djangotoolbox/commit/57a0d7cd189fa93454617bcd28dd3e6b57466e6d – lehins Apr 29 '14 at 11:41