Welcome to URLographer’s documentation!¶
URLographer is a URL mapper for the Django web framework that supplements the standard Django URL dispatch. It was designed to ease the maintenance burden of sites with large numbers of legacy URLs.
Contents:
Features¶
permanent and temporary redirects
map url to arbitrary status code
database + cache driven
automatic caching and cache invalidation on save
- URL canonicalization:
- case mismatch: (/FOO -> /foo)
- unicode encoding errors in the path
- eliminate relative paths (.././../etc)
- extra slashes (/foo//bar -> /foo/bar)
Installation¶
Using pip, preferably in a virtualenv:
pip install django-urlographer
Add urlographer to INSTALLED_APPS in your project’s setup.py:
INSTALLED_APPS = (
# ...
'urlographer',
# ...
)
Add the following to the end of your project’s urls.py:
urlpatterns += patterns('urlographer.views', ('^.*$', 'route'))
Create the necessary database tables using South:
cd /path/to/your/project
python manage.py migrate urlographer
If you don’t have South installed (we’re not sure why, but trust that you have your reasons), running python manage.py syncdb
in your project directory should also work.
Usage¶
Mapping a URL to a view¶
Create a ContentMap
with the view and
options specified, then create an URLMap
with a status_code of 200 and the content_map FK pointing to the
ContentMap
you just created.
Creating redirects¶
Create an URLMap
with the “redirect” FK
pointing to another URLMap (usually one that has already been mapped to
a view, as detailed in url-mapping) the redirect target and a
status_code of 301 or 302, depending on whether you want a permanent or
temporary redirect.
Modules¶
models
Module¶
Note
For the memcache backend, 0 means use the default_timeout, but for django-redis-cache backend, 0 means no expiration (NOT recommended)
Note
This should not include the leading ‘/’
utils
Module¶
-
urlographer.utils.
canonicalize_path
(path)¶ - Eliminate extra slashes
- Eliminate ./
- Make ../ behave as expected by eliminating parent dirs from path (but without unintentionally exposing files, of course)
- Eliminate all unicode chars using
force_ascii()
-
urlographer.utils.
force_ascii
(s)¶ Eliminate all non-ASCII characters, ignoring errors
-
urlographer.utils.
force_cache_invalidation
(request)¶ Returns true if a request from contains the Cache-Control: no-cache header
-
urlographer.utils.
get_redirect_url_with_query_string
(request, url)¶
-
urlographer.utils.
get_view
(*args, **kwds)¶ Uses similar logic to django.urlresolvers.get_callable, but always raises on failures and supports class based views.
-
urlographer.utils.
memoize
(function, *args)¶