A simple redirects utility that uses a simple 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:
.. code:: python
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:
.. code:: javascript
{
"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:
.. code:: python
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
]))
-----
Import this in urls.py and assign it to urlpatterns
BEFORE custom urls. (redirects should be hit first)
e.g:
.. code:: python
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:
.. code:: javascript
{
"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:
.. code:: python
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for django-redirects-file-0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c64f1eff1b05e5c3bb80791dc02918b8a973ffe65a614c00c8434d71180b4fd2 |
|
MD5 | 84c5f00504ba165addc2dec1ca06324f |
|
BLAKE2b-256 | a2f46707695854415a1bd2262ba5b1e9c635e9c506d006f23f77016e584f0409 |