Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing project and app templates in django

Tags:

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?

like image 745
iJK Avatar asked Aug 23 '10 00:08

iJK


People also ask

How do I add a template to Django project?

To configure the Django template system, go to the settings.py file and update the DIRS to the path of the templates folder. Generally, the templates folder is created and kept in the sample directory where manage.py lives. This templates folder contains all the templates you will create in different Django Apps.

How do I organize my Django templates?

There are two main ways to organize your template structure in Django: the default app-level way and a custom project-level approach.

What does {% %} mean in Django?

{% extends variable %} uses the value of variable . If the variable evaluates to a string, Django will use that string as the name of the parent template. If the variable evaluates to a Template object, Django will use that object as the parent template.

What is App_dirs in Django?

With APP_DIRS set to True , the template loader will look in the app's templates directory and find the templates.


2 Answers

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.

like image 148
hgcrpd Avatar answered Sep 20 '22 08:09

hgcrpd


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.

like image 44
Wolph Avatar answered Sep 19 '22 08:09

Wolph