Skip to content

Instantly share code, notes, and snippets.

@vjousse
Created September 11, 2013 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vjousse/6521823 to your computer and use it in GitHub Desktop.
Save vjousse/6521823 to your computer and use it in GitHub Desktop.
Simple django command to output django_redirect redirections to nginx format
from django.core.management.base import BaseCommand, CommandError
from django.contrib.redirects.models import Redirect
class Command(BaseCommand):
help = 'Print nginx redirections'
def handle(self, *args, **options):
for redirect in Redirect.objects.all():
self.stdout.write('rewrite ^%s$ %s permanent;' % (redirect.old_path, redirect.new_path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment