From e9b4d0c2363a79f2c1262b608020a11ee721befc Mon Sep 17 00:00:00 2001 From: Stephen Kiely Date: Wed, 20 Nov 2024 18:10:59 -0700 Subject: [PATCH] Make urls.py a file that is always baked. (#198) --- nautobot-app/hooks/post_gen_project.py | 1 - .../{{ cookiecutter.app_name }}/urls.py | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/nautobot-app/hooks/post_gen_project.py b/nautobot-app/hooks/post_gen_project.py index d99618ca..6ebc943e 100644 --- a/nautobot-app/hooks/post_gen_project.py +++ b/nautobot-app/hooks/post_gen_project.py @@ -43,7 +43,6 @@ "tests/test_form_{{ cookiecutter.model_class_name.lower() }}.py", "tests/test_model_{{ cookiecutter.model_class_name.lower() }}.py", "tests/test_views.py", - "urls.py", "views.py", ] for file in files_to_remove: diff --git a/nautobot-app/{{ cookiecutter.project_slug }}/{{ cookiecutter.app_name }}/urls.py b/nautobot-app/{{ cookiecutter.project_slug }}/{{ cookiecutter.app_name }}/urls.py index 6c4651b3..7522af5c 100644 --- a/nautobot-app/{{ cookiecutter.project_slug }}/{{ cookiecutter.app_name }}/urls.py +++ b/nautobot-app/{{ cookiecutter.project_slug }}/{{ cookiecutter.app_name }}/urls.py @@ -5,10 +5,20 @@ from django.views.generic import RedirectView from nautobot.apps.urls import NautobotUIViewSetRouter +{% if cookiecutter.model_class_name != "None" %} from {{ cookiecutter.app_name }} import views +{% else %} +# Uncomment the following line if you have views to import +# from {{ cookiecutter.app_name }} import views +{% endif %} router = NautobotUIViewSetRouter() +{% if cookiecutter.model_class_name != "None" %} router.register("{{ cookiecutter.model_class_name | lower }}", views.{{ cookiecutter.model_class_name }}UIViewSet) +{% else %} +# Here is an example of how to register a viewset, you will want to replace views.{{ cookiecutter.camel_name }}UIViewSet with your viewset +# router.register("{{ cookiecutter.app_name }}", views.{{ cookiecutter.camel_name }}UIViewSet) +{% endif %} urlpatterns = [ path("docs/", RedirectView.as_view(url=static("{{ cookiecutter.app_name }}/docs/index.html")), name="docs"),