When creating a new app or a new project, you can generate it from a
template. It will contain files, and some files can be rendered by the
template engine.
See the docs : https://docs.djangoproject.com/en/dev/ref/django-admin
/#startapp-appname-destination
I would like to add the possibility of passing extra template context,
though command line parameters.
For example, that would allows us to pass an extra variable, « author »,
in the template context… so the generated app can correctly reference the
author.
We could also use it to choose a license…
The code that needs to be modified is here :
https://github.com/django/django/blob/master/django/core/management/templates.py#L113
I think it would be quite easy to change, and I can do a patch if you
want.
What do you think about it ?
--
Ticket URL: <https://code.djangoproject.com/ticket/20741>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
I have added a patch that works.
But, my help text is far from perfect.
I also didn't understood why the content of the « options » variable was
added to the context. I have removed it for now, but I don't know if that
was the right thing to do :/
--
Ticket URL: <https://code.djangoproject.com/ticket/20741#comment:1>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/20741#comment:2>
* owner: nobody => jcatalan
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/20741#comment:3>
* status: assigned => closed
* resolution: => wontfix
Comment:
Hi,
This might be nice to have, but I'm not sure if this should be supported
by the core command itself. I would probably just make my own command
subclassing TemplateCommand and adding the options your templates need.
For instance, adding the --author option.
By doing this, as it says in the
[https://docs.djangoproject.com/en/1.4/ref/django-admin/#django-admin-
option---template docs], every additional option passed will be added to
the context. So you can call it this way:
{{{#!bash
django-admin.py my_custom_startapp --template=/mytemplate <app_name>
--author=Foo
}}}
BTW, that code you erased removing options from the context it's what will
make this work, and as far as I understand from the docs I just mentioned,
it's a desired capability, so you shouldn't remove it in your patch. I'm
closing this ticket as wontfix cause I think it's better to solve this the
way I mentioned above, which doesn't modify any code in django itself.
If this doesn't solve your issue please let me know.
Juan
--
Ticket URL: <https://code.djangoproject.com/ticket/20741#comment:4>
Comment (by palkeo):
Ok, I understand.
Thanks !
--
Ticket URL: <https://code.djangoproject.com/ticket/20741#comment:5>
Comment (by Mariusz Felisiak):
New [https://forum.djangoproject.com/t/startproject-command-context/24445
discussion] on the forum.
--
Ticket URL: <https://code.djangoproject.com/ticket/20741#comment:6>