reflex-dev/reflex · error · SystemExit
Only {template_name=} should be provided, got {template_code
Error message
Only {template_name=} should be provided, got {template_code_dir_name=}, {template_dir=}. What it means
Raised by `reflex.utils.templates.initialize_app_directory` when the default template is selected but extra template location arguments are also supplied. The DEFAULT template is bundled in local Reflex assets, so template_code_dir_name/template_dir are hard-coded internally; providing them indicates the caller misunderstood the API.
Source
Thrown at reflex/utils/templates.py:66
Args:
app_name: The name of the app.
template_name: The name of the template to use.
template_code_dir_name: The name of the code directory in the template.
template_dir: The directory of the template source files.
Raises:
SystemExit: If template_name, template_code_dir_name, template_dir combination is not supported.
"""
logger.info("Initializing the app directory.")
# By default, use the blank template from local assets.
if template_name == constants.Templates.DEFAULT:
if template_code_dir_name is not None or template_dir is not None:
logger.error(
f"Only {template_name=} should be provided, got {template_code_dir_name=}, {template_dir=}."
)
raise SystemExit(1)
template_code_dir_name = constants.Templates.Dirs.CODE
template_dir = Path(constants.Templates.Dirs.BASE, "apps", template_name)
else:
if template_code_dir_name is None or template_dir is None:
logger.error(
f"For `{template_name}` template, `template_code_dir_name` and `template_dir` should both be provided."
)
raise SystemExit(1)
logger.debug(f"Using {template_name=} {template_dir=} {template_code_dir_name=}.")
# Remove __pycache__ dirs in template directory and current directory.
for pycache_dir in [
*template_dir.glob("**/__pycache__"),
*Path.cwd().glob("**/__pycache__"),
]:
shutil.rmtree(pycache_dir, ignore_errors=True)
View on GitHub (pinned to 45b8ed5ab7)
Solutions
- Drop template_code_dir_name and template_dir arguments when using the default template; Reflex fills them from bundled assets.
- If you intended a custom/remote template, pass a non-default template_name along with both template_code_dir_name and template_dir.
Example fix
# before
initialize_app_directory(
template_name=constants.Templates.DEFAULT,
template_dir=Path("./my_template"),
template_code_dir_name="code",
)
# after
initialize_app_directory(template_name=constants.Templates.DEFAULT) Defensive patterns
Strategy: validation
Validate before calling
from reflex import constants
def validate_template_args(name, code_dir_name, template_dir):
if name == constants.Templates.DEFAULT:
assert code_dir_name is None and template_dir is None
else:
assert code_dir_name is not None and template_dir is not None Prevention
- When using the bundled default template, pass only template_name.
- Reserve template_dir/template_code_dir_name for custom or remote templates.
When it happens
Trigger: Calling initialize_app_directory(template_name=constants.Templates.DEFAULT ('default'), ...) with a non-None template_code_dir_name or template_dir. Typically reached via initialize_default_app or create_config_init_app_from_remote_template wiring arguments incorrectly.
Common situations: Custom scaffolding code that always passes template_dir regardless of template name; copy-pasted calls from remote-template code paths into default-template paths.
Related errors
- For `{template_name}` template, `template_code_dir_name` and
- Only one of `data` or `fp` may be provided, not both.
- At least one of `data` or `fp` must be provided.
- Cannot use --single-port with --frontend-only or --backend-o
- Failed to create temp directory for download: {ose}
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/3946c584d6c0f4d1.
Report an issue: GitHub.