2017-06-15 171 views
0

我100%确定我的路径在我的代码中是正确的,为什么它给我TemplateDoesNotExist错误?我看不出这是可能的。为什么我的index.html文件不能在目录中找到?

我想:

settings.py > TEMPLATES > Dirs: [/template/music]

和其他东西上SO一箩筐,但它不纠正我的问题。

enter image description here

这是我的views.py文件:

from django.http import HttpResponse 
from django.template import loader 

def index(request): 
    template = loader.get_template('music/index.html') 
    return HttpResponse(template.render()) 

def detail(request, user_id): # Testing out page 2 
    return HttpResponse("<h2>Page # (testing this out) " + str(user_id) + "</h2>") 

这是我的index.html文件:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <title>The Page</title> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
</head> 

<body> 
    <div class="container"> 
     <form action="#"> 
      <div class="form-group"> 
       <label for="firstName">First Name:</label> 
       <input type="email" class="form-control" id="firstName" placeholder="Enter first name" name="firstName"> 
      </div> 
      <div class="form-group"> 
       <label for="">Last Name:</label> 
       <input type="email" class="form-control" id="lastName" placeholder="Enter last name" name="lastName"> 
      </div> 
     </form> 
      <div class="checkbox"> 
       <label><input type="checkbox" name="remember">Remember me</label></div></br> 
       <button type="submit" class="btn btn-default">Submit</button> 
      </div> 
    </div> 
</body> 
</html> 
+0

在设置你有模板,但名称是模板。并且是migrations文件夹内的模板文件夹? – Exprator

回答

3

你的模板目录内迁移。将它移出那里。

+0

刚刚写了一篇文章,详细说明了各种语法,直到我看到这个,正确的答案。 –

+0

非常愚蠢的我,谢谢。这对我有用。 – bojack

相关问题