Trying to include app urls, can't get it working
kirmola opened this issue · 2 comments
Hi there, I am currently trying to add urls by including them like
distill_path('', include("maintools.urls"), name="maintoolsurls"),
but can't get it working ,its throwing an error.
Traceback (most recent call last):
File "C:\Users\Aman Rawat\Desktop\work\django\amancodes\env\lib\site-packages\django_distill\renderer.py", line 244, in generate_uri
uri = reverse(view_name, args=param_set)
File "C:\Users\Aman Rawat\Desktop\work\django\amancodes\env\lib\site-packages\django\urls\base.py", line 86, in reverse
return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
File "C:\Users\Aman Rawat\Desktop\work\django\amancodes\env\lib\site-packages\django\urls\resolvers.py", line 698, in _reverse_with_prefix
raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'maintoolsurls' not found. 'maintoolsurls' is not a valid view function or pattern name.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Aman Rawat\Desktop\work\django\amancodes\manage.py", line 22, in <module>
main()
File "C:\Users\Aman Rawat\Desktop\work\django\amancodes\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\Aman Rawat\Desktop\work\django\amancodes\env\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\Aman Rawat\Desktop\work\django\amancodes\env\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Aman Rawat\Desktop\work\django\amancodes\env\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Aman Rawat\Desktop\work\django\amancodes\env\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Users\Aman Rawat\Desktop\work\django\amancodes\env\lib\site-packages\django_distill\management\commands\distill-local.py", line 83, in handle
render_to_dir(output_dir, urls_to_distill, stdout)
File "C:\Users\Aman Rawat\Desktop\work\django\amancodes\env\lib\site-packages\django_distill\renderer.py", line 382, in render_to_dir
for page_uri, file_name, http_response in renderer.render():
File "C:\Users\Aman Rawat\Desktop\work\django\amancodes\env\lib\site-packages\django_distill\renderer.py", line 192, in render_all_urls
uri = self.generate_uri(url, view_name, param_set)
File "C:\Users\Aman Rawat\Desktop\work\django\amancodes\env\lib\site-packages\django_distill\renderer.py", line 246, in generate_uri
uri = reverse(view_name_ns, args=param_set)
File "C:\Users\Aman Rawat\Desktop\work\django\amancodes\env\lib\site-packages\django\urls\base.py", line 86, in reverse
return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
File "C:\Users\Aman Rawat\Desktop\work\django\amancodes\env\lib\site-packages\django\urls\resolvers.py", line 698, in _reverse_with_prefix
raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'maintoolsurls' not found. 'maintoolsurls' is not a valid view function or pattern name.
It says no reverse found. However this page is working perfectly when seen on browser.
Can you please help??
This is for django-distill
isn't it? Regardless, you just need to specify the namespace in your include(...)
as per the docs:
https://docs.djangoproject.com/en/dev/ref/urls/#django.urls.include
Try
distill_path('', include("maintools.urls", namespace="maintools"), name="maintoolsurls"),
Or something like that, whatever the namespace is. As for why this works in a browser but not in django-distill
, django-distill
can only know the namespace when rendering if it's specified explicitly where as some of the Django internals can determine it automatically on page load. This information is not available to django-distill
as the URLs are cached when Django starts up.
You can also see an example of namespaced URLs working in the django-distill
tests:
https://github.com/meeb/django-distill/blob/master/tests/namespaced_urls.py#L25