未在模板页

时间:2018-05-04 16:45:14

标签: django django-templates django-views

我试图获取单个记录的详细信息,以便在Django的模板页面上显示,但我看不到任何内容

我的urls.py

from django.contrib import admin
from django.urls import path
from calendarapp import views

urlpatterns = [
    path('', views.index, name='index'),
    path('flight/<int:pk>', views.details, name='details'),
    path('admin/', admin.site.urls),
]

我的views.py

from django.shortcuts import render
from .models import Flight

def index(request):

    flights = Flight.objects.all()[:5]

    return render(request, 'calendarapp/index.html', {'flights': flights})

def details(request, pk):

    flight = Flight.objects.get(id=pk)

    return render(request, 'calendarapp/index.html', {'flight': flight})

我的模板页面

{% extends 'calendarapp/base.html' %}

<div class='container'>
  {% block content %}
    <p>departure time - {{ id.dep_time }}</p>
    <p>departure delay - {{ flight.dep_delay }}</p>
    <p>arrival time - {{ flight.arr_time }}</p>
    <p>arrival delay - {{ flight.arr_delay }}</p>
    <p>cancelled - {{ flight.cancelled }}</p>
    <p>carrier - {{ flight.carrier }}</p>
    <p>tail number - {{ flight.tailnum }}</p>
    <p>flight - {{ flight.flight }}</p>
    <p>origin - {{ flight.origin }}</p>
    <p>destination - {{ flight.dest }}</p>
    <p>air time - {{ flight.air_time }}</p>
    <p>distance - {{ flight.distance }} km</p>
    <p>duration - {{ flight.duration }}</p>
  {% endblock %}
</div>

我不确定为什么我的详细信息没有显示?

0 个答案:

没有答案