evileg_core.decorators module

evileg_core.decorators.non_login_required(function=None, redirect_url='/')[source]

Decorator for views that checks that the user is not logged in, redirecting to the main page or target page by redirect_url if user is logged in.


Google recaptcha decorator. It can be used against robots and brute force.


function – wrapped view function, which should be checked via Google recaptcha


wrapped function


Using recaptcha

  1. Add recaptcha key to

GOOGLE_RECAPTCHA_SECRET_KEY = 'your-secret-token'
  1. Add recaptcha to view in urls

from django.conf.urls import url
from evileg_core.decorators import recaptcha

from . import views

app_name = 'registration'
urlpatterns = [
    url(r'^register/$', recaptcha(views.RegisterView.as_view()), name='register'),
  1. Add recaptcha site key in template with form

<form action="{% url 'register' %}" method="post">
    {% csrf_token %}
    {{ form.as_p }}
    {% load evileg_core %}
    {% recaptcha %}
    {% if messages %}
        {% for message in messages %}
            {{ message }}
        {% endfor %}
    {% endif %}
    <input type="submit" value="Register">
  1. Check recaptcha in your form view

class RegisterView(FormView):
    form_class = UserCreationForm
    template_name = 'register.html'

    def form_valid(self, form):
        if self.request.recaptcha_is_valid:
            return render(self.request, 'register_success.html', self.get_context_data())
        return render(self.request, 'register.html', self.get_context_data())