Repository: imAsparky/django-cookiecutter

Issue:
[BUG]: Generated Django has 4 errors listed below.
**Describe the bug**
A clear and concise description of what the bug is.

secret key settings needs [ ]
need  'django.contrib.sites', in INSTALLED_APPS
SITE_ID has rendered as str, must be int.
LANGUAGES  is not rendering correctly.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**

-   imAsparky cookiecutter-pypackage version:
-   Python version:
-   OS: [e.g. iOS]
-   Browser [e.g. chrome, safari]
-   Version [e.g. 22]

**Smartphone (please complete the following information):**

-   Device: [e.g. iPhone6]
-   OS: [e.g. iOS8.1]
-   Browser [e.g. stock browser, safari]
-   Version [e.g. 22]

**Additional context**
Add any other context about the problem here.



Discussion:

Resolving patch:
diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py
--- a/hooks/pre_gen_project.py
+++ b/hooks/pre_gen_project.py
@@ -36,12 +36,12 @@
     )
 
 # fmt: off
-if "{{ cookiecutter.USE_I18N }}" == "y":
-    assert (   # nosec
-        len(LANGUAGES) > 0
-    ), "'USE_I18N' True with empty LANGUAGES list."
-else:
-    assert (  # nosec
-        len(LANGUAGES) == 1
-    ), "'USE_I18N' False with entries in LANGUAGES list."
+# if "{{ cookiecutter.USE_I18N }}" == "True":
+#     assert (   # nosec
+#         len(LANGUAGES) > 0
+#     ), "Pregen-error: 'USE_I18N' True with empty LANGUAGES list."
+# else:
+#     assert (  # nosec
+#         len(LANGUAGES) <= 1
+#     ), "Pregen-error: 'USE_I18N' False with entries in LANGUAGES list."
 # fmt: on
diff --git a/{{cookiecutter.git_project_name}}/{{cookiecutter.project_slug}}/settings.py b/{{cookiecutter.git_project_name}}/{{cookiecutter.project_slug}}/settings.py
--- a/{{cookiecutter.git_project_name}}/{{cookiecutter.project_slug}}/settings.py
+++ b/{{cookiecutter.git_project_name}}/{{cookiecutter.project_slug}}/settings.py
@@ -11,6 +11,7 @@
 
 from pathlib import Path
 import os
+from django.utils.translation import ugettext_lazy as _
 
 # Build paths inside the project like this: BASE_DIR / 'subdir'.
 BASE_DIR = Path(__file__).resolve().parent.parent
@@ -20,10 +21,11 @@
 # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
 
 # SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = os.environ("DJANGO_SECRET_KEY")
+SECRET_KEY = os.environ.get(
+    'DJANGO_SECRET_KEY', '!!!SET DJANGO_SECRET_KEY!!!')
 
 # SECURITY WARNING: don't run with debug turned on in production!
-DEBUG = "{{cookiecutter.DEBUG}}"
+DEBUG = {% if cookiecutter.DEBUG == 'True' %}True{% else %}False{% endif %}
 
 ALLOWED_HOSTS = ["{{cookiecutter.ALLOWED_HOSTS}}"]
 
@@ -36,17 +38,23 @@
     "django.contrib.auth",
     "django.contrib.contenttypes",
     "django.contrib.sessions",
+    "django.contrib.sites",
     "django.contrib.messages",
     "django.contrib.staticfiles",
 {% if cookiecutter.use_django_allauth == "y" %}
     "allauth",
     "allauth.account",
     "allauth.socialaccount",
+
+    'allauth.socialaccount.providers.github',
+    'allauth.socialaccount.providers.google',
 {% endif %}
 ]
-
-SITE_ID = "{{cookiecutter.SITE_ID}}"
-
+{% if cookiecutter.SITE_ID == "1" %}
+SITE_ID = 1
+{% else %}
+SITE_ID = {{cookiecutter.SITE_ID}}
+{% endif %}
 MIDDLEWARE = [
     "django.middleware.security.SecurityMiddleware",
     "django.contrib.sessions.middleware.SessionMiddleware",
@@ -78,7 +86,6 @@
         },
     },
 ]
-
 {% if cookiecutter.use_django_allauth == "y" %}
 AUTHENTICATION_BACKENDS = [
 
@@ -89,10 +96,8 @@
     'allauth.account.auth_backends.AuthenticationBackend',
 ]
 {% endif %}
-
 WSGI_APPLICATION = "{{ cookiecutter.project_slug}}.wsgi.application"
 
-
 # Database
 # https://docs.djangoproject.com/en/3.2/ref/settings/#databases
 
@@ -103,7 +108,6 @@
     }
 }
 
-
 # Password validation
 # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
 
@@ -122,25 +126,53 @@
     },
 ]
 
-
 # Internationalization
 # https://docs.djangoproject.com/en/3.2/topics/i18n/
+{%- set language_labels = ({
+    "en": "English",
+    "cn": "Chinese",
+    "fr": "French",
+    "de": "German",
+    "hi": "Hindi",
+    "it": "Italian",
+    "jp": "Japanese",
+    "ru": "Russian",
+    "es": "Spanish",
+}) %}
+{% if cookiecutter.USE_I18N == "True" %}
+{% if cookiecutter.USE_L10N == "True" %}
+USE_L10N = True
+{% else %}
+USE_L10N = False
+{% endif %}
+USE_I18N = True
 
 LANGUAGE_CODE = "{{cookiecutter.LANGUAGE_CODE}}"
 
-LANGUAGES = "{{cookiecutter.LANGUAGES}}"
+{%- with languages = cookiecutter.LANGUAGES.replace(' ', '').split(',') %}
 
-TIME_ZONE = "{{cookiecutter.TIME_ZONE}}"
-
-USE_I18N = "{{cookiecutter.USE_I18N}}"
-
-USE_L10N = "{{cookiecutter.USE_L10N}}"
+LANGUAGES = [{% for language in languages %}
+    ('{{ language }}', _("{{ language_labels[language] }}")),{% endfor %}
+]
+{% endwith %}
 
 USE_TZ = True
 
 TIME_ZONE = "{{cookiecutter.TIME_ZONE}}"
+{% else %}
+{% if cookiecutter.USE_L10N == "True" %}
+USE_L10N = True
+{% else %}
+USE_L10N = False
+{% endif %}
+USE_I18N = False
 
+LANGUAGE_CODE = "{{cookiecutter.LANGUAGE_CODE}}"
+
+USE_TZ = True
 
+TIME_ZONE = "{{cookiecutter.TIME_ZONE}}"
+{% endif %}
 # Static files (CSS, JavaScript, Images)
 # https://docs.djangoproject.com/en/3.2/howto/static-files/
 


Test patch:
diff --git a/tests/test_bake_django.py b/tests/test_bake_django.py
--- a/tests/test_bake_django.py
+++ b/tests/test_bake_django.py
@@ -3,14 +3,16 @@
 import datetime
 import os
 from test_helper import bake_checker
+from cookiecutter import exceptions
 
 
 def test_django_bakes_ok_with_defaults(cookies):
     """Test cookiecutter created the Django project ok."""
+
     default_django = cookies.bake()
 
-    assert default_django.project_path.is_dir()
     assert default_django.exit_code == 0
+    assert default_django.project_path.is_dir()
     assert default_django.exception == None
     assert default_django.project_path.name == "django-boilerplate"
 
@@ -783,18 +785,20 @@ def test_baked_django_settings_file_ok(cookies):
     default_django = cookies.bake()
 
     settings_path = default_django.project_path / "django_boilerplate/settings.py"
+
     settings_file = settings_path.read_text().splitlines()
 
     assert '"""Django settings for django-boilerplate project.' in settings_file
     assert 'ALLOWED_HOSTS = ["www.example.com"]' in settings_file
-    assert 'DEBUG = "False"' in settings_file
+    assert 'INTERNAL_IPS = ["127.0.0.1"]' in settings_file
+    assert "DEBUG = False" in settings_file
     assert 'ROOT_URLCONF = "django_boilerplate.urls"' in settings_file
     assert 'WSGI_APPLICATION = "django_boilerplate.wsgi.application"' in settings_file
-    assert 'LANGUAGE_CODE = "en-au"' in settings_file
-    assert 'LANGUAGES = "hi"' in settings_file
+    assert 'LANGUAGE_CODE = "en"' in settings_file
+    assert "    ('en', _(\"English\"))," in settings_file
     assert 'TIME_ZONE = "UTC"' in settings_file
-    assert 'USE_I18N = "True"' in settings_file
-    assert 'USE_L10N = "True"' in settings_file
+    assert "USE_I18N = True" in settings_file
+    assert "USE_L10N = True" in settings_file
 
 
 def test_baked_django_urls_file_ok(cookies):