I have a suggestion to make here and, if you consider that it can be useful, I can try to develop this feature to contribute in this project.
I face the problem that I can do “python manage.py startproject --template xxx -e py,yml,toml” to create a project based on my template and overwriting the info in py, yml and toml files. That is almost perfect…
Imagine that, I am using docker and I want to overwrite in there the version of python to build. I want to specify the version (or another info, this is just an example) when I create the template. Something like this:
python manage.py startproject --template xxx -e py,yml,toml -c python_version=3.11 -c using_drf=true ...
This makes the templating much more powerful and this can be applied to startapp command too.
Later, if this suggestion go foward, we can discuss if adding context variables to default templates to do something like
startapp -c add_urls=true -c test_as_module=true <name> could solve some recurring topics
I read in this ticket:
I would probably just make my own command subclassing TemplateCommand and adding the options your templates need
And was closed for that. But it has no sense at all because this command is to start a new project/app so, in this case, you can’t subclass this command because you don’t have a project to do this.
I suspect that this idea would be rejected, in favour of recommending a fully-featured option like cookiecutter.
Super powerful things are possible:
Django’s own tool is never going to approach the power of this, and there seems little point adding much complication for an incomplete offering, when the more powerful tool is already there for folks who need it.
Copier is another tool that even allows updates of the generated project and manage the whole lifecycle. Maybe we should prominently point people to copier/cookiecutter/yeoman (Comparisons - copier) in the docs for the template argument.
I agree with you, Cookiecutter is an incredible tool but this is not built-in with django and it “forces” you to do it outside django itself
Another idea/possibility can be the integration of a battle-tested tool like cookiecutter when you use the startproject/startapp CLI. This could bring to django the interactive CLI to create project/apps that it deserves.
As I imagine this, when you use this command it install the dependency of cookiecutter and throw a selector of “django official templates” and, when you select the one you need, the cli starts asking about the variables or configurations required.
This integration could end some recurring threads as:
- startapp with urls
- creating (or not) an “apps” folder to encapsulate in a sublevel the django apps to have the main folder appart
- The name of the main folder equal to the project name, some people rename it as main/config/project…
- Use as “microservice” giving the minimal structure to work like minimal django
- and much more…
I think the reality is that we’re limited in what we have capacity to maintain…
There are a number of project templates out there in the community, but it’s not realistic that we could (even) keep a list updated in the docs, so folks need to rely on searching and the likes of Awesome Django.
I like the idea of suggesting alternative tools to people. (I hadn’t heard of Copier!)
In terms of workload I agree with you at all.
The suggestion of alternatives is a good point. @apollo13 was right.