Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#20741 closed New feature (wontfix)

Add extra context to templates of « start{app,project} » management commands

Reported by: palkeo Owned by: jcatalan
Component: Core (Management commands) Version: 1.5
Severity: Normal Keywords:
Cc: contact@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: yes UI/UX: no

Description

Hi,

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 ?

Attachments (1)

patch.diff (1.4 KB) - added by palkeo 2 years ago.

Download all attachments as: .zip

Change History (6)

Changed 2 years ago by palkeo

comment:1 Changed 2 years ago by palkeo

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 :/

comment:2 Changed 2 years ago by palkeo

  • Has patch set
  • Patch needs improvement set

comment:3 Changed 2 years ago by jcatalan

  • Owner changed from nobody to jcatalan
  • Status changed from new to assigned

comment:4 Changed 2 years ago by jcatalan

  • Resolution set to wontfix
  • Status changed from assigned to closed

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 docs, every additional option passed will be added to the context. So you can call it this way:

  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

comment:5 Changed 2 years ago by palkeo

Ok, I understand.
Thanks !

Note: See TracTickets for help on using tickets.
Back to Top