0
私は、このような
Django TemplateDoesNotExist?
exception: TemplateDoesNotExist
を取得してサーバを実行
Django TemplateDoesNotExist? Running the server i get such
exception: TemplateDoesNotExist
models.py
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
GENDER_CHOICES = (("M","MALE"),("F","FEMALE"))
user = models.OneToOneField(User)
gender = models.CharField(max_length=6, choices=GENDER_CHOICES, default="M")
Age = models.IntegerField()
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTim``eField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
views.py
from django.shortcuts import render
from django.http import HttpResponse
from django.http import HttpResponseRedirect
# Create your views here.
def index(request):
return HttpResponse("Hello, You are in the core index.")
def detail(request, question_id):
return HttpResponse("You're looking at question %s." % question_id)
def results(request, question_id):
response = "You're looking at the results of question %s."
return HttpResponse(response % question_id)
def vote(request, question_id):
return HttpResponse("You're voting on question %s." % question_id)
from .models import Question
from django.template import loader
# def index(request):
# latest_question_list = Question.objects.order_by('-pub_date') [:5]
#output = '<br>'.join([q.question_text for q in latest_question_list])
# return HttpResponse(output)
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
template = loader.get_template('core/index.html')
context = {
'latest_question_list': latest_question_list,
}
return HttpResponse(template.render(context, request))
で
settings.pyファイルにプロジェクトファイルの構造、テンプレートフォルダの場所とTEMPLATES設定を表示します。 –