Skip to main content
https://badge.fury.io/py/django-icase.svg https://travis-ci.org/bennylope/django-icase.svg?branch=master https://coveralls.io/repos/bennylope/django-icase/badge.svg?branch=master

A few tools for helping with case-insensitvity in Django URLs.

  • 404 handler that redirects non-matched, non-lowercase URLs. E.g. if /About/ is not matched, the handler will redirect to /about/ before returning a 404

  • Middleware that enforces lower-cased URLs. E.g. all non-lowercased URLs will be redirected to their lowercased form.

Overview

If you only need to match URL patterns, then it’s simple to add case-insensitivity to your regular expressions.:

urlpatterns = patterns('',
    (r'^(?i)admin/(.*)', admin.site.root),
    (r'^(?i)static/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': settings.STATIC_DOC_ROOT, 'show_indexes': True}),
    (r'^(?i)login/$', 'django.contrib.auth.views.login'),
    (r'^(?i)logout/$', do_logout),
)

From Alex Martelli’s Stack Overflow explanation.

However this doesn’t do anything to match slugs, which are often case-sensitive matched by default - it’s up to the app. If the app uses a straightforward = expression, e.g.:

object = MyModel.objects.get(slug=slug)

Then MySlug won’t match myslug.

There are also instances where you want to enforce URL casing for other reasons (or a client does!).

Installation

Install django-icase:

pip install django-icase

To use the custom 404 handler, simply specify this in your project urls.py configuration.:

handler404 = 'icase.views.icase_404_handler'

To use the lowercasing middleware, add it to your INSTALLED_MIDDLEWARE.:

INSTALLED_MIDDLEWARE = (
    'icase.middleware.LowerCased',
    ...
)

Django & Python support

Actively supported versions of Django are supported by this app, although there is little reason it should not work on others.

Tested against Python 3 and Python 2.7.9.

History

0.1.1 (2015-05-06)

  • Update django-nose reference to support Django 1.7+

0.1.0 (2015-03-25)

  • First release on PyPI.

Release files for django-icase 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-icase 0.1.1
File Size Uploaded
django-icase-0.1.1.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-icase 0.1.1
File Interpreter ABI Platform
django_icase-0.1.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size:14.2 kB

Release files / django-icase-0.1.1.tar.gz

Download URL django-icase-0.1.1.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f831dfe7e095467fa5d74931ea790e7bf87b7dc30185e3f6ec4a2edfaea356e2
BLAKE2b-256 checksum
How to use checksums
37a94389e19f2c3d5910770e85573b4a8a6757f4e85b26d1211dac8505ebf396
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_icase-0.1.1-py2.py3-none-any.whl

Download URL django_icase-0.1.1-py2.py3-none-any.whl
Size 8.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
411d3f3fd2aedfd10f14b887338d90074461470aa1be722374867922184dc76e
BLAKE2b-256 checksum
How to use checksums
a266be3f966d94b734993e9c89923a9a32e358b7d853e9d95e932a3b5f59b7fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page