TemplateDoesNotExist位于http://127.0.0.1:8000/

时间:2020-03-05 15:01:56

标签: django django-views django-templates

我不知道为什么会收到此错误。下面是我正在使用的代码。

settings.py

TEMPLATE_DIRS = (os.path.join(os.path.dirname(BASE_DIR), "mysite", "static", "templates"),)

urls.py

from django.urls import path
from django.conf.urls import include, url
from django.contrib.auth import views as auth_views
from notes import views as notes_views

urlpatterns = [
    url(r'^$', notes_views.home, name='home'),
    url(r'^admin/', admin.site.urls),
]```


**views.py**


`def home(request):
    notes = Note.objects
    template = loader.get_template('note.html')
    context = {'notes': notes}
    return render(request, 'templates/note.html', context)`

NOTE : I am following this tutorial -  https://pythonspot.com/django-tutorial-building-a-note-taking-app/

2 个答案:

答案 0 :(得分:0)

您使用哪个版本的Django?该教程看起来已经过时了。

首先在您的settings.py中设置DEBUG = True-它会向您显示更多信息。

答案 1 :(得分:0)

return render(request, 'templates/note.html', context)

尝试从上面的行中删除模板/,这样行中只有模板'note.html':

return render(request, 'note.html', context)