Skip to content

Instantly share code, notes, and snippets.

@jneight
Last active December 20, 2015 03:09
Show Gist options
  • Save jneight/6061844 to your computer and use it in GitHub Desktop.
Save jneight/6061844 to your computer and use it in GitHub Desktop.
Given a uri with the form /api/v1/class/1/ get the view and args it will call from registered urls
from django.core.urlresolvers import (
reverse, get_script_prefix, resolve, Resolver404)
prefix = get_script_prefix()
chomped_uri = uri
if prefix and chomped_uri.startswith(prefix):
chomped_uri = chomped_uri[len(prefix) - 1:]
# resolve will split cleaned uri and get PK
view, args, extra_venue = resolve(chomped_uri)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment