Skip to main content

Django URL converters

Project description

django-urlconverter: Django automatic view parameters conversion

The django-urlconverter package provides an easy way to convert view arguments from simple types to complex ones, like models, or just do some processing using robust syntax. Most interesting application of the package is to convert view arguments which are object ids (from database via ORM) to the instances of those objects (Models).


pip install django-urlconverter


from django.db import models

class FooBar(models.Model):
    """Foo Bar model."""
    title = models.CharField(max_length=100)

from .models import FooBar

class Foo(object):
    """Foo converter. Convert an object id to FooBar instance."""
    def __init__(self, **kwargs):
        self.kwargs = kwargs

    def __call__(self, value, request, *args, **kwargs):
        return FooBar.objects.get(pk=value)

    'Foo': 'converters.Foo',  # Converts to 'FooBar instance'

from django.conf.urls.defaults import patterns
from django_urlconverter import converted_arguments_url

urlpatterns = patterns('views',
    converted_arguments_url(r'^foos/<Foo:foo2>/', 'bar'),

def bar(request, foo2):
    """View function which gets a converted foo2.
    the foo2 will be a converted parameter, which is the result of Foo converter
    return foo2.title


If you have questions, bug reports, suggestions, etc. please create an issue on the GitHub project page.


This software is licensed under the MIT license


© 2013 Paylogic International.



  • Initial public release

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-urlconverter-1.0.0.tar.gz (5.5 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page