Skip to content

Instantly share code, notes, and snippets.

@cnk
Created March 26, 2020 16:16
Show Gist options
  • Save cnk/5f19a1a9b241776c909b7f5877a0f89e to your computer and use it in GitHub Desktop.
Save cnk/5f19a1a9b241776c909b7f5877a0f89e to your computer and use it in GitHub Desktop.
# Shell plus session
In [3]: reverse('public:survey')
Out[3]: '/commuter_survey/'
In [4]: reverse('admin:survey-index')
---------------------------------------------------------------------------
NoReverseMatch Traceback (most recent call last)
<ipython-input-4-21bbf73985d4> in <module>
----> 1 reverse('admin:survey-index')
/ve/lib64/python3.6/site-packages/django/urls/base.py in reverse(viewname, urlconf, args, kwargs, current_app)
85 resolver = get_ns_resolver(ns_pattern, resolver, tuple(ns_converters.items()))
86
---> 87 return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
88
89
/ve/lib64/python3.6/site-packages/django/urls/resolvers.py in _reverse_with_prefix(self, lookup_view, _prefix, *args, **kwargs)
675 "a valid view function or pattern name." % {'view': lookup_view_s}
676 )
--> 677 raise NoReverseMatch(msg)
NoReverseMatch: Reverse for 'survey-index' not found. 'survey-index' is not a valid view function or pattern name.
In [5]: resolve('/commuter_survey/admin/surveys')
Out[5]: ResolverMatch(func=commuter_survey.core.views.admin_survey.survey_index, args=(), kwargs={}, url_name=survey-index, app_names=['core'], namespaces=['admin'], route=commuter_survey/admin/surveys)
[root@commuter_survey app]# ./manage.py show_urls
/commuter_survey/ commuter_survey.core.views.public.survey_view public:survey
/commuter_survey/admin/surveys commuter_survey.core.views.admin_survey.survey_index admin:survey-index
/commuter_survey/complete commuter_survey.core.views.public.survey_complete public:survey-complete
/commuter_survey/server_status commuter_survey.core.views.public.server_status public:server-status
/django-admin/ django.contrib.admin.sites.index django-admin:index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment