Copy either a Django application layout template or a Django project layout template into the specified directory.
Attributes
| Attribute | Type | Description |
|---|
| requires_system_checks | list = [] | List of system checks that must be performed before the command is executed. |
| url_schemes | list = ["http", "https", "ftp"] | The supported URL schemes for downloading remote templates. |
| rewrite_template_suffixes | tuple = ((".py-tpl", ".py"),) | Rewrite the following suffixes when determining the target filename. |
Constructor
Signature
Methods
add_arguments()
@classmethod
def add_arguments(
parser: [CommandParser](../base/commandparser.md?sid=django_core_management_base_commandparser)
)
Configures the command line argument parser with options for project/app names, target directories, templates, and file filtering.
Parameters
| Name | Type | Description |
|---|
| parser | [CommandParser](../base/commandparser.md?sid=django_core_management_base_commandparser) | The argument parser instance to which the command-specific arguments will be added. |
handle()
@classmethod
def handle(
app_or_project: str,
name: str,
target: str = null,
options: dict
)
Executes the template copying logic, including directory creation, context rendering for Python files, and permission management.
Parameters
| Name | Type | Description |
|---|
| app_or_project | str | A string indicating whether to create an 'app' or a 'project'. |
| name | str | The name of the new application or project to be created. |
| target | str = null | The optional destination directory path where the template should be unpacked. |
| options | dict | Additional command line arguments including verbosity, extensions, and file exclusions. |
handle_template()
@classmethod
def handle_template(
template: str,
subdir: str
) - > str
Determine where the app or project templates are. Use django.path[0] as the default because the Django install directory isn't known.
Parameters
| Name | Type | Description |
|---|
| template | str | The path, URL, or file URI provided by the user to load the template from. |
| subdir | str | The default subdirectory name within the Django core to look for if no template is specified. |
Returns
| Type | Description |
|---|
str | The absolute local file path to the directory containing the template files. |
validate_name()
@classmethod
def validate_name(
name: str,
name_or_dir: str = name
)
Validates that the provided name is a valid Python identifier and does not conflict with existing modules.
Parameters
| Name | Type | Description |
|---|
| name | str | The identifier string to validate for the new app or project. |
| name_or_dir | str = name | A label used in error messages to specify if the validation failed for a name or a directory. |
download()
@classmethod
def download(
url: str
) - > str
Download the given URL and return the file name.
Parameters
| Name | Type | Description |
|---|
| url | str | The remote URL from which to fetch the template archive. |
Returns
| Type | Description |
|---|
str | The local file path to the downloaded template archive. |
splitext()
@classmethod
def splitext(
the_path: str
) - > tuple
Like os.path.splitext, but takes off .tar, too
Parameters
| Name | Type | Description |
|---|
| the_path | str | The file path or filename to be split into base and extension. |
Returns
| Type | Description |
|---|
tuple | A tuple containing the base filename and the full extension (e.g., '.tar.gz'). |
@classmethod
def extract(
filename: str
) - > str
Extract the given file to a temporary directory and return the path of the directory with the extracted content.
Parameters
| Name | Type | Description |
|---|
| filename | str | The path to the archive file that needs to be extracted. |
Returns
| Type | Description |
|---|
str | The path to the temporary directory containing the extracted files. |
is_url()
@classmethod
def is_url(
template: str
) - > bool
Return True if the name looks like a URL.
Parameters
| Name | Type | Description |
|---|
| template | str | The string to check for a URL scheme. |
Returns
| Type | Description |
|---|
bool | True if the string starts with a supported URL scheme, False otherwise. |
apply_umask()
@classmethod
def apply_umask(
old_path: str,
new_path: str
)
Applies the current system umask to the new file based on the permissions of the source file.
Parameters
| Name | Type | Description |
|---|
| old_path | str | The path to the original template file used to read source permissions. |
| new_path | str | The path to the newly created file where permissions will be applied. |
make_writeable()
@classmethod
def make_writeable(
filename: str
)
Make sure that the file is writeable. Useful if our source is read-only.
Parameters
| Name | Type | Description |
|---|
| filename | str | The path of the file to modify to ensure user write permissions. |