Skip to content

Instantly share code, notes, and snippets.

@zjjott
Last active August 29, 2015 14:13
Show Gist options
  • Save zjjott/fbcfa17c02205eb405d3 to your computer and use it in GitHub Desktop.
Save zjjott/fbcfa17c02205eb405d3 to your computer and use it in GitHub Desktop.
make request in django have endpoint like flask
# coding=utf-8
from django.http import Http404
from django.core.urlresolvers import resolve
class EndPointMiddleware(object):
"""make request in django have endpoint like flask"""
def process_request(self, request):
try:
match = resolve(request.path)
if hasattr(match, 'view_name'):
request.endpoint = match.view_name
else:
request.endpoint = ''
except Http404:
request.endpoint = ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment