iJK
iJK

Reputation: 4765

Customizing project and app templates in django

I would like to customize the files and folders created when running

python manage.py startapp appname

I find doing some things over and over again and I think it would be neat, if my customizations are present when I create a new app.

Do you know where I can customize the default files when an app is created?

Upvotes: 11

Views: 4536

Answers (4)

srj
srj

Reputation: 10141

If you are using an older version of django, you can write your custom django-admin command, as illustrated here. you could write modification of startapp, which creates your custom files.

Upvotes: 2

hgcrpd
hgcrpd

Reputation: 1900

startapp and startproject accept a --template flag with which you can specify a directory or compressed file that the command should use as a template for you new app or project. It also passes in a context with your app/project name that you can insert into your templates with template tags.

See https://docs.djangoproject.com/en/dev/ref/django-admin/#startapp-appname-destination for the details.

It looks like this was added in 1.4.

Upvotes: 16

laurent
laurent

Reputation: 908

You can copy your customized files instead of using the created ones without problem.

Upvotes: 2

Wolph
Wolph

Reputation: 80061

The files are in django/conf/app_template and django/conf/project_template for the app and project files respectively.

I don't think there is a ways to override this location without either creating your own startapp / startproject command or without modifying django/core/management/base.py.

Upvotes: 7

Related Questions