Created
March 15, 2018 16:38
-
-
Save erichurkman/3b327f435814130a508737f8f127d397 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env bash | |
./manage.py shell -c "\ | |
import re | |
import sys | |
from django.urls import NoReverseMatch, Resolver404, resolve | |
urls = ['$1'] | |
if not '$1'.endswith('/'): | |
urls.append('$1/') | |
for url in urls: | |
try: | |
r = resolve(url) | |
except (NoReverseMatch, Resolver404): | |
print('No match for: $1') | |
else: | |
print('Match for: {}'.format(url)) | |
print('{}.{}'.format(r.func.__module__, r.func.__name__)) | |
for namespace in r.namespaces: | |
if hasattr(r.func, 'view_class'): | |
template_name = getattr(r.func.view_class, 'template_name', None) | |
if template_name: | |
print(' template_name: templates/{}'.format(template_name)) | |
bundle_name = getattr(r.func.view_class, 'bundle', None) | |
if bundle_name: | |
entries = open('entries.js', 'r').readlines() | |
for line in entries: | |
if bundle_name in line: | |
print(' bundle: {}'.format(line.strip())) | |
print(' url_name: {}:{}'.format(namespace, r.url_name)) | |
print(' args: {!r}'.format(r.args)) | |
print(' kwargs: {!r}'.format(r.kwargs)) | |
break | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment