简体   繁体   中英

Django 3.1 How to solve template mapping in settings.py

As you can see in the below Django code of settings.py I'm trying to map the templates with it, but I can't be able to that. When I am running the server it is showing the error

from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent.parent

DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'first_project.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

Terminal:Here is the full error list in the below. I think There is something what I missing to add them, but I don't understand.

Traceback (most recent call last):
  File "manage.py", line 22, in <module>main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)

  File "C:\Users\user\anaconda3\envs\myDjangoEnv\lib\site-packages\django\core
\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\user\anaconda3\envs\myDjangoEnv\lib\site-packages\django\core
\management\__init__.py", line 345, in execute
    settings.INSTALLED_APPS
  File "C:\Users\user\anaconda3\envs\myDjangoEnv\lib\site-packages\django\conf
\__init__.py", line 83, in __getattr__
    self._setup(name)
File "C:\Users\user\anaconda3\envs\myDjangoEnv\lib\site-packages\django\conf
\__init__.py", line 70, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Users\user\anaconda3\envs\myDjangoEnv\lib\site-packages\django\conf

\__init__.py", line 177, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File"C:\Users\user\anaconda3\envs\myDjangoEnv\lib\importlib\__init__.py", l
ine 127, in import_module

  File"C:\Users\user\Desktop\Django\first_project\first_project\settings.py",
 line 17
BASE_DIR = Path(__file__).resolve().parent.parent
^
IdentationError: unexpected error

Probably something unrelated to syntax but related to CRLF vs LF or whatever can't be seen, reformat using a formatter or delete all spaces manually and add them again

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM