English 中文(简体)
django : recaptcha : Error in firefox works in IE & chrome : RecaptchaState error
原标题:

I have integrated Recaptcha with dJango. dJango Snippet - Recaptcha

The view which is showing the page is - from baseapp.recaptcha import captcha

def showHome(request):    
    if(request.user.is_authenticated()):    
        tempEmail = request.session.get( id )    
        return render_to_response( logreg/login-register.html ,   { emailFromForm :tempEmail}, context_instance=RequestContext(request));    
    else:    
        request.session.set_test_cookie()    
        form = RegistrationForm()    
        loginForm = LoginForm()    
        html_captcha = captcha.displayhtml(settings.RECAPTCHA_PUB_KEY)    
        print "Captcha HTML is : %s" % html_captcha    
        return render_to_response( logreg/login-register.html , { form : form,  loginForm :loginForm,  html_captcha :html_captcha})    `

Here is the code in html -

<div id="register-dialog" title="Register yourself">    
  <p id="validateTips">All form fields are required.</p>    
  {% if error %}    
  {{ error }}    
  {% endif %}    
  <form name="registrationForm" action="registerUser/" method="post">    
      {{ form.as_p }}    
      {{ html_captcha }}    
  </form>    
</div>

It works great in IE & Chrome, but firefox shows me an exception at line 451 in recaptcha. Here is the code at that line var $ST = RecaptchaState;

Any thoughts are appreciated !

Note : Firefox version - 3.6; IE - 8; Chrome - 4.0

最佳回答

Here is how I solved it.

I figured that my captcha is being shown inside the jqueryui dialog and maybe that is the problem with FF. (Why ? I don t know.) Hence instead of statically putting the text there from django or writing it out. I used the ajax api and inserted the recaptcha on the open event on the dialog.

Here is the sample code, just in case someone stumbles upon the same issue.

Code is almost similar to what is on the reCaptcha api site

$("#register-dialog").dialog({    
    buttons:{
    },    
    open: function() {
    Recaptcha.create("41x39....",
        "recaptcha_div", {
        theme: "red",
        callback: Recaptcha.focus_response_field
        });

And changed the form tag to be so -

<form name="registrationForm" action="registerUser/" method="post">    
    {{ form.as_p }}    
    <div id="recaptcha_div"></div>    
</form>

And yes, included the ajax.js -

    <script type="text/javascript" src="http://api.recaptcha.net/js/recaptcha_ajax.js">
    </script>
问题回答

暂无回答




相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签