Skip to main content

A simple redirects utility that uses a json file for redirects definitions

Project description

Usage

Import this in urls.py and assign it to urlpatterns BEFORE custom urls. (redirects should be hit first) e.g:

from django_redirects_file import load_redirects

urlpatterns = load_redirects()
urlpatterns += patterns('',
    url(r'^(?P<template>.*)/?$', TemplateFinder.as_view()),
)

Format of redirects.json

The json format is simply key/value pairs, from source to destination:

{
    "getubuntu/download_static": "http://www.ubuntu.com/netbook/get-ubuntu/download",
    "testing/quantal/alpha1":    "https://wiki.ubuntu.com/QuantalQuetzal/TechnicalOverview/Alpha1"
}

To convert old “double spaced” redirects.txt:

json.dumps(dict([
    i.split('  ')[0:2] #ignore the 3rd item, in-line comments
    for i in open('/path/to/redirects.txt').readlines()
    if len(i.split('  ')) >= 2 #ignore whole comment lines
]))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-redirects-file-0.1.1.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file django-redirects-file-0.1.1.tar.gz.

File metadata

File hashes

Hashes for django-redirects-file-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8ada702daa7c0d824b185149e7850e6a7c8bbcbff002cbed8fabf7d18667c625
MD5 1e662c10824cf24bf84ab38e672e7853
BLAKE2b-256 8f5bbd6c6f800a1c416e25321d71dd0d6085acd9080164a54e6065d60b66f8d6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page