Repository: wagtail/wagtail

Issue:
Support for custom templates in `wagtail start` command
Previously discussed in [A command line Blog generator OR UI based predefined templates to select. #10221](https://github.com/wagtail/wagtail/discussions/10221) (and elsewhere I’m sure). And on today’s core team meeting.

Extend the `wagtail start` command to support providing a template, like the underlying `django startproject` already supports ([link to our implementation](https://github.com/wagtail/wagtail/blob/main/wagtail/bin/wagtail.py#L92-103)). This would then allow us to provide website templates in a more Wagtail-branded-y way, compared to cookiecutter and other project scaffolding / boilerplate tools.

We’re very keen to make use of this as part of an upcoming Google Summer of Code project where we’d like to help people make low-carbon / ["GOLD"](https://github.com/wagtail/wagtail/discussions/8843) websites.

---

Once this is set up, types of sites we could make templates for:

Site type:

- Blog
- Brochure site
- E-commerce
- https://github.com/APSL/puput

Tech:

- Bootstrap
- HTMX
- Tailwind
Support for custom templates in `wagtail start` command
Previously discussed in [A command line Blog generator OR UI based predefined templates to select. #10221](https://github.com/wagtail/wagtail/discussions/10221) (and elsewhere I’m sure). And on today’s core team meeting.

Extend the `wagtail start` command to support providing a template, like the underlying `django startproject` already supports ([link to our implementation](https://github.com/wagtail/wagtail/blob/main/wagtail/bin/wagtail.py#L92-103)). This would then allow us to provide website templates in a more Wagtail-branded-y way, compared to cookiecutter and other project scaffolding / boilerplate tools.

We’re very keen to make use of this as part of an upcoming Google Summer of Code project where we’d like to help people make low-carbon / ["GOLD"](https://github.com/wagtail/wagtail/discussions/8843) websites.

---

Once this is set up, types of sites we could make templates for:

Site type:

- Blog
- Brochure site
- E-commerce
- https://github.com/APSL/puput

Tech:

- Bootstrap
- HTMX
- Tailwind


Discussion:
e.g. `wagtail start my_blog --template https://github.com/tomdyson/wagtail-blog-starter`

perhaps starters in the Github Wagtail org could be 'blessed' and not require the full URL?

`wagtail start my_blog --template wagtail-blog-starter`
e.g. `wagtail start my_blog --template https://github.com/tomdyson/wagtail-blog-starter`

perhaps starters in the Github Wagtail org could be 'blessed' and not require the full URL?

`wagtail start my_blog --template wagtail-blog-starter`

Resolving patch:
diff --git a/wagtail/bin/wagtail.py b/wagtail/bin/wagtail.py
--- a/wagtail/bin/wagtail.py
+++ b/wagtail/bin/wagtail.py
@@ -58,6 +58,9 @@ def execute(self, argv):
 class CreateProject(Command):
     description = "Creates the directory structure for a new Wagtail project."
 
+    def __init__(self):
+        self.default_template_path = self.get_default_template_path()
+
     def add_arguments(self, parser):
         parser.add_argument("project_name", help="Name for your Wagtail project")
         parser.add_argument(
@@ -65,8 +68,20 @@ def add_arguments(self, parser):
             nargs="?",
             help="Destination directory inside which to create the project",
         )
+        parser.add_argument(
+            "--template",
+            help="The path or URL to load the template from.",
+            default=self.default_template_path,
+        )
+
+    def get_default_template_path(self):
+        import wagtail
+
+        wagtail_path = os.path.dirname(wagtail.__file__)
+        default_template_path = os.path.join(wagtail_path, "project_template")
+        return default_template_path
 
-    def run(self, project_name=None, dest_dir=None):
+    def run(self, project_name=None, dest_dir=None, **options):
         # Make sure given name is not already in use by another python package/module.
         try:
             __import__(project_name)
@@ -79,24 +94,20 @@ def run(self, project_name=None, dest_dir=None):
                 "name. Please try another name." % project_name
             )
 
+        template_name = options["template"]
+        if template_name == self.default_template_path:
+            template_name = "the default Wagtail template"
+
         print(  # noqa: T201
-            "Creating a Wagtail project called %(project_name)s"
-            % {"project_name": project_name}
+            "Creating a Wagtail project called %(project_name)s using %(template_name)s"
+            % {"project_name": project_name, "template_name": template_name}
         )
 
-        # Create the project from the Wagtail template using startapp
-
-        # First find the path to Wagtail
-        import wagtail
-
-        wagtail_path = os.path.dirname(wagtail.__file__)
-        template_path = os.path.join(wagtail_path, "project_template")
-
         # Call django-admin startproject
         utility_args = [
             "django-admin",
             "startproject",
-            "--template=" + template_path,
+            "--template=" + options["template"],
             "--ext=html,rst",
             "--name=Dockerfile",
             project_name,


Test patch: