fix: fixed secret key not generated

This commit is contained in:
sankalp committed 2026-03-01 00:27:47 +05:45
1 parent e24fb36dea
commit 68f1b44eab
3 files changed
+29 -10

No files matched your search

+5 -3
View File
@@ -18,7 +18,7 @@ logger = logging.getLogger(__name__)
app = typer.Typer(
help="djinit - A CLI tool to set up Django projects with best practices.",
add_completion=False,
no_args_is_help=True,
no_args_is_help=False,
)
@@ -33,8 +33,9 @@ def version_callback(value: bool):
raise typer.Exit()
@app.callback()
@app.callback(invoke_without_command=True)
def main(
ctx: typer.Context,
version: Annotated[
Optional[bool],
typer.Option("--version", "-v", callback=version_callback, is_eager=True, help="Show the version and exit."),
@@ -43,7 +44,8 @@ def main(
"""
djinit: Django Project Initializer
"""
pass
if ctx.invoked_subcommand is None:
setup()
@app.command("secret")
+1 -1
View File
@@ -27,7 +27,7 @@ class ProjectCreator(BaseService):
os.makedirs(self.project_root, exist_ok=True)
unified = self.metadata.get("unified_structure", False)
DjangoHelper.startproject(self.module_name, self.project_root, unified=unified)
DjangoHelper.startproject(self.module_name, self.project_root, unified=unified, metadata=self.metadata)
UIFormatter.print_success(f"Django project '{self.project_name}' created successfully!")
def _get_apps_base_dir(self) -> str:
+23 -6
View File
@@ -14,8 +14,10 @@ class DjangoHelper:
DJANGO_VERSION = DJANGO_VERSION
@staticmethod
def startproject(project_name: str, directory: str, unified: bool = False) -> None:
def startproject(project_name: str, directory: str, unified: bool = False, metadata: dict = None) -> None:
try:
from djinit.utils.secretkey import generate_secret_key
os.makedirs(directory, exist_ok=True)
manage_py_path = os.path.join(directory, "manage.py")
@@ -33,11 +35,26 @@ class DjangoHelper:
settings_dir = os.path.join(project_config_dir, "settings")
CommonUtils.create_directory_with_init(settings_dir, f"Created {project_name}/settings/__init__.py")
base_context = {"project_name": project_name, "app_names": []}
# Generate secret key for development
secret_key = generate_secret_key()
metadata = metadata or {}
base_context = {
"project_name": project_name,
"app_names": [],
"use_database_url": metadata.get("use_database_url", True),
"database_type": metadata.get("database_type", "postgresql"),
}
dev_context = {"secret_key": secret_key}
# Production context also needs database info
prod_context = base_context.copy()
settings_files = [
("base.py", "config/settings/base.py-tpl", base_context),
("development.py", "config/settings/development.py-tpl", {}),
("production.py", "config/settings/production.py-tpl", {}),
("development.py", "config/settings/development.py-tpl", dev_context),
("production.py", "config/settings/production.py-tpl", prod_context),
]
CommonUtils.create_files_from_templates(settings_dir, settings_files, f"{project_name}/settings/")
@@ -48,8 +65,8 @@ class DjangoHelper:
}
project_files = [
("urls.py", "config/urls.py-tpl", urls_context),
("wsgi.py", "config/wsgi.py-tpl", {}),
("asgi.py", "config/asgi.py-tpl", {}),
("wsgi.py", "config/wsgi.py-tpl", {"project_name": project_name}),
("asgi.py", "config/asgi.py-tpl", {"project_name": project_name}),
]
CommonUtils.create_files_from_templates(project_config_dir, project_files, f"{project_name}/")