Django,找不到模板

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

我正在尝试呈现此HTML文件(主页),但收到未找到模板的错误。

#views.py
from django.shortcuts import render


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

from django.contrib import admin
from django.urls import path, include

from . import views

urlpatterns = [
    path('', views.index, name='Home'),
]

错误:

TemplateDoesNotExist at /
templates/index.html

这只会加载一个空白页面:

from django.shortcuts import render


def index(request):
    """Homepage"""
    return render(request, 'index.html')

我的HTML文件

我猜这里可能缺少某种链接。我还向DIRS和设置中添加了'os.path.join(BASE_DIR,“ templates”)',该页面仍然为空白。

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<a href="{% url 'index' %}">Home</a>.

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

    <title>Triangulation Calculator</title>
  </head>
  <body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
  <div class="container">
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <ul class="navbar-nav ml-auto">
        <li class="nav-item active">
          <a class="nav-link" href="#">Home
                <span class="sr-only">(current)</span>
              </a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Three Positions Triangulation</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Second </a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Add Known Location</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

<section class="py-5 text-center">
      <div class="container"> 
        <h2 class="text-center">Triangulation Calculator</h2>
        <p class="text-muted mb-5 text-center">There's three Features here, below, you'll find explaintion for each.</p>
        <div class="row">
          <div class="col-sm-6 col-lg-4 mb-3">
            <svg class="lnr text-primary services-icon">
              <use xlink:href="#lnr-magic-wand"></use>
            </svg>
            <h6>Three Positions Triangulation</h6>
            <p class="text-muted">Naming is All, Choose a grate name for your mission so you can come back and open that map whenever you want.
                You input the latitude and longitude for GDT 1, GDT 2 and the location of the UAV, also, we need the
                elevation of the uav above sea level, where do you get that data?
                Thank God for Google.
                go to google maps, when you press a location on the map you can the coordinates as we need them, in the following format:
                31.4531,35.56243.
                first is latitude and longitude, copy the values to calculator.
                done?
                press POST
                the page will refresh and you'll see all your data.
                go to the address line and add the mission name to the and of the line.
                KABLAM!
                Your map will open.</p>
          </div>
          <div class="col-sm-6 col-lg-4 mb-3">
            <svg class="lnr text-primary services-icon">
              <use xlink:href="#lnr-heart"></use>
            </svg>
            <h6>Second GDT options</h6>
            <p class="text-muted">Second option works a lot the same: Input your mission name and the data for GDT 1 and the UAV, and choose the area of the mission.
                and the rest is the same.
                How does the map work here?
                if you hover your mouse over one of the numbers you'll see the boundaries of that triangulation, the more you zoom in,
                the more detailed it gets.</p>
          </div>
          <div class="col-sm-6 col-lg-4 mb-3">
            <svg class="lnr text-primary services-icon">
              <use xlink:href="#lnr-rocket"></use>
            </svg>
            <h6>Add Location Info to the DataBase</h6>
            <p class="text-muted">Here you input a base,outpost,mountain or just every location you ever put a GDT in.
                choose the area where that position lies.
                and every time someone will use the second option, we'll automatically add those positions to the map.</p>
          </div>
          </div>
        </div>
      </div>
</section>
  </body>
</html>
python django
1个回答
0
投票
TEMPLATE_DIR = os.path.join(BASE_DIR,'templates')

并在settings.py中找到模板和目录作为字典文件,添加此

DIRS = ['TEMPLATE_DIR',]

或者直接您可以像这样添加DIRS

DIRS = ['os.path.join(BASE_DIR,'templates')

并根据我的回答确保目录名称是模板而不是模板

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