Last active
August 29, 2015 14:13
-
-
Save zjjott/fbcfa17c02205eb405d3 to your computer and use it in GitHub Desktop.
make request in django have endpoint like flask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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