为什么我的index.html文件不能在目录中找到?

问题描述 投票:0回答:1

我100%确定我的路径在我的代码中是正确的,为什么它给我TemplateDoesNotExist错误?我看不出这是怎么可能的。

我试过了:

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>
python django
1个回答
3
投票

您的模板目录位于迁移内。把它移出那里。

© www.soinside.com 2019 - 2024. All rights reserved.