mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #17042 -- Extended startproject and startapp management commands to better handle custom app and project templates. Many thanks to Preston Holmes for his initial patch and Alex Gaynor, Carl Meyer, Donald Stufft, Jacob Kaplan-Moss and Julien Phalip for code reviewing.
* Added ability to pass the project or app directory path as the second argument * Added ``--template`` option for specifying custom project and app templates * Cleaned up admin_scripts tests a little while I was there git-svn-id: http://code.djangoproject.com/svn/django/trunk@17246 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -99,8 +99,7 @@ Prints the DROP TABLE SQL statements for the given app name(s).
|
||||
Prints the custom SQL statements for the given app name(s).
|
||||
.TP
|
||||
.BI "sqlflush [" "appname ..." "]"
|
||||
Prints the SQL statements that would be executed for the "flush"
|
||||
command.
|
||||
Prints the SQL statements that would be executed for the "flush" command.
|
||||
.TP
|
||||
.BI "sqlindexes [" "appname ..." "]"
|
||||
Prints the CREATE INDEX SQL statements for the given model module name(s).
|
||||
@@ -116,13 +115,13 @@ name(s).
|
||||
Prints the SQL statements for resetting PostgreSQL sequences for the
|
||||
given app name(s).
|
||||
.TP
|
||||
.BI "startapp [" "appname" "]"
|
||||
.BI "startapp [" "\-\-template=PATH_OR_URL" "] [" "\-\-extension=EXTENSION" "] [" "appname" "] [" "destination" "]"
|
||||
Creates a Django app directory structure for the given app name in
|
||||
the current directory.
|
||||
the current directory or the optional destination.
|
||||
.TP
|
||||
.BI "startproject [" "projectname" "]"
|
||||
.BI "startproject [" "\-\-template=PATH_OR_URL" "] [" "\-\-extension=EXTENSION" "] [" "projectname" "] [" "destination" "]"
|
||||
Creates a Django project directory structure for the given project name
|
||||
in the current directory.
|
||||
in the current directory or the optional destination.
|
||||
.TP
|
||||
.BI syncdb
|
||||
Creates the database tables for all apps in INSTALLED_APPS whose tables
|
||||
@@ -194,7 +193,7 @@ The locale to process when using makemessages or compilemessages.
|
||||
The domain of the message files (default: "django") when using makemessages.
|
||||
.TP
|
||||
.I \-e, \-\-extension=EXTENSION
|
||||
The file extension(s) to examine (default: ".html", separate multiple
|
||||
The file extension(s) to examine (separate multiple
|
||||
extensions with commas, or use -e multiple times).
|
||||
.TP
|
||||
.I \-s, \-\-symlinks
|
||||
@@ -214,6 +213,9 @@ Don't break long message lines into several lines.
|
||||
.I \-a, \-\-all
|
||||
Process all available locales when using makemessages..SH "ENVIRONMENT"
|
||||
.TP
|
||||
.I \-a, \-\-template=PATH_OR_URL
|
||||
The file or directory path or URL to load the project and app templates from.
|
||||
.TP
|
||||
.I DJANGO_SETTINGS_MODULE
|
||||
In the absence of the
|
||||
.BI \-\-settings
|
||||
|
||||
@@ -907,21 +907,121 @@ of sync with its automatically incremented field data.
|
||||
The :djadminopt:`--database` option can be used to specify the database for
|
||||
which to print the SQL.
|
||||
|
||||
startapp <appname>
|
||||
------------------
|
||||
startapp <appname> [destination]
|
||||
--------------------------------
|
||||
|
||||
.. django-admin:: startapp
|
||||
|
||||
Creates a Django app directory structure for the given app name in the current
|
||||
directory or the given destination.
|
||||
|
||||
.. versionchanged:: 1.4
|
||||
|
||||
By default the directory created contains a ``models.py`` file and other app
|
||||
template files, see the `source`_ for more details. If only the app
|
||||
name is given, the app directory will be created in the current working
|
||||
directory.
|
||||
|
||||
startproject <projectname>
|
||||
--------------------------
|
||||
If the optional destination is provided, it will be used to create the
|
||||
the new app directory in. The use of '.' to denote the current working
|
||||
directory is valid for the destination. For example::
|
||||
|
||||
django-admin.py startapp myapp /Users/jezdez/Code
|
||||
|
||||
|
||||
.. versionadded:: 1.4
|
||||
.. django-admin-option:: --template
|
||||
|
||||
With the ``--template`` option you can use a custom app template by providing
|
||||
either the path to a directory with the app template file, a path to a
|
||||
compressed file (``.tar.gz``, ``.tar.bz2``, ``.tgz``, ``.tbz``, ``.zip``)
|
||||
containing the app template files.
|
||||
|
||||
Additionally Django will also accept URLs (``http``, ``https``, ``ftp``) to
|
||||
compressed archives with the app template files, downloading and extracting
|
||||
them on the fly.
|
||||
|
||||
For example, this would look for an app template in the given directory when creating the ``myapp`` app::
|
||||
|
||||
django-admin.py startapp --template=/Users/jezdez/Code/my_app_template myapp
|
||||
|
||||
.. versionadded:: 1.4
|
||||
|
||||
When Django copies the app template files it will also render the files
|
||||
whose extension matches those passed with the ``--extension`` option (``py``
|
||||
by default) using the template engine. The :class:`template context
|
||||
<django.template.Context>` used is:
|
||||
|
||||
- Any option passed to the startapp command
|
||||
- ``app_name`` -- the appp name as passed to the command
|
||||
- ``app_directory`` -- the full path of the newly created app
|
||||
|
||||
.. _render_warning:
|
||||
|
||||
.. warning::
|
||||
|
||||
When the app template files are rendered with the Django template
|
||||
engine (by default all ``*.py`` files) it will also replace all
|
||||
stray template variables contained. If one of the Python files for
|
||||
example contains a docstring explaining a particular feature related
|
||||
to template rendering, it might result in an incorrect example.
|
||||
|
||||
To work around this problem you can use the :ttag:`templatetag`
|
||||
templatetag to "escape" the various parts of the template syntax.
|
||||
|
||||
.. _source: https://code.djangoproject.com/browser/django/trunk/django/conf/app_template/
|
||||
|
||||
startproject <projectname> [destination]
|
||||
----------------------------------------
|
||||
|
||||
.. django-admin:: startproject
|
||||
|
||||
Creates a Django project directory structure for the given project name in the
|
||||
current directory.
|
||||
Creates a Django project directory structure for the given project name in
|
||||
the current directory or the given destination.
|
||||
|
||||
.. versionchanged:: 1.4
|
||||
|
||||
By default the directory created contains a ``manage.py`` file and a project
|
||||
package (containing ``settings.py`` file and other project template files),
|
||||
see the `template source`_ for more details.
|
||||
|
||||
If only the project name is given, both the project directory and project
|
||||
package will be named ``<projectname>`` and the project directory
|
||||
will be created in the current working directory.
|
||||
|
||||
If the optional destination is provided, it will be used to create the
|
||||
the new project directory in. The use of '.' to denote the current working
|
||||
directory is valid for the destination. For example::
|
||||
|
||||
django-admin.py startproject myproject /Users/jezdez/Code
|
||||
|
||||
.. versionadded:: 1.4
|
||||
|
||||
Similar to the :djadmin:`startapp` command the ``--template`` option is also
|
||||
available for specifying a directory or file path of a custom project
|
||||
template. See the :djadmin:`startapp` documentation for details of supported
|
||||
project template formats.
|
||||
|
||||
For example, this would look for a project template in the given directory
|
||||
when creating the ``myproject`` project::
|
||||
|
||||
django-admin.py startproject --template=/Users/jezdez/Code/my_project_template myproject
|
||||
|
||||
When Django copies the project template files it will also render the files
|
||||
whose extension matches those passed with the ``--extension`` option (``py``
|
||||
by default) using the template engine. The :class:`template context
|
||||
<django.template.Context>` used is:
|
||||
|
||||
- Any option passed to the startproject command
|
||||
- ``project_name`` -- the project name as passed to the command
|
||||
- ``project_directory`` -- the full path of the newly created project
|
||||
- ``secret_key`` -- a random key for the :setting:`SECRET_KEY` setting
|
||||
|
||||
Please also see the :ref:`rendering warning <render_warning>` as mentioned
|
||||
for :djadmin:`startapp`.
|
||||
|
||||
.. _`template source`: https://code.djangoproject.com/browser/django/trunk/django/conf/project_template/
|
||||
|
||||
|
||||
syncdb
|
||||
------
|
||||
|
||||
@@ -429,6 +429,27 @@ callable :djadmin:`runserver` uses.
|
||||
(The :djadmin:`runfcgi` management command also internally wraps the WSGI
|
||||
callable configured via :setting:`WSGI_APPLICATION`.)
|
||||
|
||||
Custom project and app templates
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The :djadmin:`startapp` and :djadmin:`startproject` management commands
|
||||
got a ``--template`` option for specifying paths or URL to custom app or
|
||||
project templates.
|
||||
|
||||
For example, Django will use the ``/path/to/my_project_template``
|
||||
directorywhen running the following command::
|
||||
|
||||
django-admin.py startproject --template=/path/to/my_project_template myproject
|
||||
|
||||
Additionally you can now provide a destination directory as the second
|
||||
argument to both :djadmin:`startapp` and :djadmin:`startproject`::
|
||||
|
||||
django-admin.py startapp myapp /path/to/new/app
|
||||
django-admin.py startproject myproject /path/to/new/project
|
||||
|
||||
For more information see the :djadmin:`startapp` and :djadmin:`startproject`
|
||||
documentation.
|
||||
|
||||
Support for time zones
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
@@ -420,6 +420,27 @@ callable :djadmin:`runserver` uses.
|
||||
(The :djadmin:`runfcgi` management command also internally wraps the WSGI
|
||||
callable configured via :setting:`WSGI_APPLICATION`.)
|
||||
|
||||
Custom project and app templates
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The :djadmin:`startapp` and :djadmin:`startproject` management commands
|
||||
got a ``--template`` option for specifying paths or URL to custom app or
|
||||
project templates.
|
||||
|
||||
For example, Django will use the ``/path/to/my_project_template``
|
||||
directorywhen running the following command::
|
||||
|
||||
django-admin.py startproject --template=/path/to/my_project_template myproject
|
||||
|
||||
Additionally you can now provide a destination directory as the second
|
||||
argument to both :djadmin:`startapp` and :djadmin:`startproject`::
|
||||
|
||||
django-admin.py startapp myapp /path/to/new/app
|
||||
django-admin.py startproject myproject /path/to/new/project
|
||||
|
||||
For more information see the :djadmin:`startapp` and :djadmin:`startproject`
|
||||
documentation.
|
||||
|
||||
Support for time zones
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user