A django application that tries to eliminate annoying things in the Django framework.
Python Shell
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.



This django application eliminates certain annoyances in the Django framework.


Installation instructions

  • Copy the annoying directory to your django project or put in on your PYTHONPATH.
  • You can also run python setup.py install, easy_install django-annoying, or pip install django-annoying.
  • Add "annoying" under INSTALLED_APPS in your settings.py file.
  • Django-annoying requires Django 1.11 or later.


render_to decorator

from annoying.decorators import render_to

# 1. Template name in decorator parameters

def foo(request):
    bar = Bar.object.all()
    return {'bar': bar}

# equals to
def foo(request):
    bar = Bar.object.all()
    return render_to_response('template.html',
                                {'bar': bar},

# 2. Template name as TEMPLATE item value in return dictionary

def foo(request, category):
    template_name = '%s.html' % category
    return {'bar': bar, 'TEMPLATE': template_name}

#equals to
def foo(request, category):
    template_name = '%s.html' % category
    return render_to_response(template_name,
                                {'bar': bar},

signals decorator

Note: signals is deprecated and will be removed in a future version. Django now includes this by default.

from annoying.decorators import signals

# connect to registered signal
def sighandler(instance, **kwargs):

# connect to any signal
signals.register_signal(siginstance, signame) # and then as in example above


@signals(siginstance, sender=YourModel)
def sighandler(instance, **kwargs):

#In any case defined function will remain as is, without any changes.

ajax_request decorator

The ajax_request decorator converts a dict or list returned by a view to a JSON or YAML object, depending on the HTTP Accept header (defaults to JSON, requires PyYAML if you want to accept YAML).

from annoying.decorators import ajax_request

def my_view(request):
    news = News.objects.all()
    news_titles = [entry.title for entry in news]
    return {'news_titles': news_titles}

autostrip decorator

Note: autostrip is deprecated and will be removed in a future version. Django now includes this by default.

from annoying.decorators import autostrip

class PersonForm(forms.Form):
    name = forms.CharField(min_length=2, max_length=10)
    email = forms.EmailField()

get_object_or_None function

from annoying.functions import get_object_or_None

def get_user(request, user_id):
    user = get_object_or_None(User, id=user_id)
    if not user:


from annoying.fields import AutoOneToOneField

class MyProfile(models.Model):
    user = AutoOneToOneField(User, primary_key=True)
    home_page = models.URLField(max_length=255, blank=True)
    icq = models.IntegerField(blank=True, null=True)


Note that if you're using Postgres you can use the built-in django.contrib.postgres.fields.JSONField, or if you're using MySQL/MariaDB you can use Django-MySQL's JSONField.

from annoying.fields import JSONField

class Page(models.Model):
    data = JSONField(blank=True, null=True)

# view or another place..
page = Page.objects.get(pk=5)
page.data = {'title': 'test', 'type': 3}

get_config function

from annoying.functions import get_config

ADMIN_EMAIL = get_config('ADMIN_EMAIL', 'default@email.com')

StaticServer middleware

Add this middleware as first item in MIDDLEWARE_CLASSES(or MIDDLEWARE)


MIDDLEWARE_CLASSES = (  # MIDDLEWARE if you're using the new-style middleware

It will serve static files in debug mode. Also it helps when you debug one of your middleware by responding to static requests before they get to debugged middleware and will save you from constantly typing "continue" in debugger.

get_object_or_this function

from annoying.functions import get_object_or_this

def get_site(site_id):
    base_site = Site.objects.get(id=1)

    # Get site with site_id or return base site.
    site = get_object_or_this(Site, base_site, id=site_id)


    return site