What is the best location to put templates in django project?

后端 未结 9 608
情歌与酒
情歌与酒 2020-12-07 13:29

What is the best location to put templates in django project?

9条回答
  •  时光说笑
    2020-12-07 13:47

    DJANGO 1.11

    add templates folder where the manage.py exist,which is your base directory. change the DIRS for TEMPLATES as following in your settings.py

    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    
    TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(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',
            ],
        },
    },
    

    ]

    Now to use the template by using the code ,

    def home(request):
        return render(request,"index.html",{})
    

    in views.py. this works completely fine for django 1.11

提交回复
热议问题