简体   繁体   中英

How will I connect my index.html to my views.py?

I tried doing this: 在此处输入图像描述

from django.http import HttpResponse
from django.shortcuts import render

def home(request):
    return render(request, 'templates/index.html')

But my page says that TemplateDoesNotExist.

在此处输入图像描述

What should I do?

Create a folder 'justcolor' under templates directory and save index.html in it. change path to 'justcolor/index.html'. return render(request, 'justcolor/index.html')

Make sure you have configured urls.py and views.py correctly.

This question is already answered here: Django TemplateDoesNotExist?

Make a templates\justColor subdirectory template inside your justColor folder and move index.html to there. Then as @Neeraj said you can change render call to render(request, 'justColor/index.html') .

(Although you should read this part of the django tutorial which will help you more than any trial-and-error in this subject: https://docs.djangoproject.com/en/3.0/intro/tutorial03/ )

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