如何在Django模板中修复此错误?

时间:2018-09-26 13:06:04

标签: django django-templates

我的模板有错误。我试图查看我出了什么问题,但无法确定该错误。

这是index.1.html:

{% extends 'clinic/clinicbase.html' %}
{% load static %}
{% block content %}
{% if username %}
    <div class="jumbotron">
        <div class="container">
            <h3>Welcome, Dr {{ name }}</h3>
            <p>You can manage your clinics here:</p>
            <p><a class="btn btn-primary btn-sm" href="#" role="button">Learn more »</a></p>
        </div>
    </div>
    {% if nodoc}
        {% if clinics %}
            {% for clinic in clinics %}
            <div class="col-sm-8 card-deck">
                <div class="card mb-3 mr-3 ml-3 shadow bg-white rounded">
                    <div class="card-body">
                        <div id="id" style="display: none;">{{ clinic.clinicid }} </div>
                        <h2 class="card-title">
                            <a href="/appointments/doctor/{{ doc.docid}}"> {{ clinic.name}}</a>
                            </a>
                        </h2>
                        <h6 class="card-subtitle mb-2 text-muted">Label: <a href="/clinic/{{ clinic.label }}/">{{ clinic.label }}</a></h6>
                        <p class="card-text">Phone: <a href="tel:{{ clinic.mobile }}">{{ clinic.mobile }}</a></p>
                        <p class="card-text">About Clinic: {{ clinic.about }}</p>
                        <p class="card-text">Website: <a href="{{ clinic.website }}">{{ clinic.website }}</a></p>
                        <div id="docbtngp" class="d-flex flex-row">
                            <a href="/appointments/doctor/edit/{{ doc.docid }}" class="btn btn-primary mr-1 mybtndocedit" data-id="{{ doc.docid }}">
                                <i class="fas fa-user-edit"></i>
                            </a>
                            <a href="/appointments/doctor/appointments/{{ doc.docid }}" class="btn btn-primary mr-1 mybtnviewapp"
                                data-id="{{ doc.docid }}">
                                <i class="fas fa-calendar"></i>
                            </a>
                            <a href="/appointments/doctor/appointment/add/{{ doc.docid }}" class="btn btn-primary mr-1 mybtnaddapp"
                                data-id="{{ doc.docid }}">
                                <i class="fas fa-calendar-plus"></i>
                            </a>
                            <a href="/appointments/doctor/remove/{{ doc.docid }}" class="btn btn-danger mr-1 mybtndel" data-id="{{ doc.docid }}">
                                <i class="fas fa-trash-alt"></i>
                            </a>

                        </div>
                    </div>

                </div>
            </div>
            {% endfor %}
        {% else %}
            <div class="alert alert-danger" role="alert">
            You are not a member of any clinic. If you are an administrator, you can add yourself to a clinic <a href="/clinic/permissions">here</a>.
            </div>   
        {% endif %}
    {% else %}
    <div class="alert alert-danger" role="alert">
        You are not registered as a doctor in the system. Please contact Support..
    </div>
    {% endif %}
{% else %}
<div class="container bg-light">
<p>You are not authorized. Please <a href="/accounts/login/?next=/clinic">login.</a></p>
{% endif %}
</div>
{% endblock %}

这是clinic / clinicbase.html:

{% load static %}
<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    {% include "clinic/common_css.html" %}    
    {% block cssblock %}
    {% endblock %}

    <title>{% block title %}{% endblock %}</title>
</head>

<body>
    <div id="navbar">
        {% block navbar %}
        {% include "clinic/topbar.html" with screen="newappointment" %}
        {% endblock %}
    </div>


    <nav aria-label="breadcrumb">
        <ol id="breadcrumb" class="breadcrumb">
            {% block breadcrumb %}{% endblock %}    
        </ol>
    </nav>

        {% block content %}
        {% endblock %}


    {% include "clinic/common_js.html" %}    
    {% block jsblock %}    
    {% endblock %}
</body>

</html>

clinic / topbar.html:

<header>
    <nav class="navbar navbar-expand-lg navbar-light" style="background-color: #e3f2fd;">
        <a class="navbar-brand" href="/"><i class="fas fa-plus"></i> Mysite</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
            aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav mr-auto">
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"
                        aria-expanded="false">
                        <i class="fas fa-user-md"></i> Clinic
                    </a>
                    <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                        <a class="dropdown-item" href="/clinic/"><i class="fas fa-car"></i> Waiting Patients</a>
                        <a class="dropdown-item" href="/clinic/seen" id="BtnPatientsSeen"><i class="fas fa-check-square"></i>
                            Seen Patients</a>
                        <a class="dropdown-item" href="/clinic/newclinic" id="AddNewClinic"><i class="fas fa-check-square"></i>
                                Add new clinic</a>
                        <a class="dropdown-item" href="/clinic/clinics" id="ListClinics"><i class="fas fa-check-square"></i>
                            Show Clinics</a>
                        <a class="dropdown-item" href="/clinic/permissions" id="SetPermissions"><i class="fas fa-check-square"></i>
                            Set mapping and permissions</a>                              

                    </div>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"
                        aria-expanded="false">
                        <i class="fas fa-address-book"></i> Registration
                    </a>
                    <div class="dropdown-menu" aria-labelledby="navbarDropdown">

                        <a class="dropdown-item" href="/clinic/register" id="registration"><i class="fas fa-clipboard"></i>
                            Register Patient</a>
                        <a class="dropdown-item" href="/clinic/checkin"><i class="fas fa-clipboard-check"></i> Checkin Patient</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" id="listRegistered" href="#"><i class="fas fa-list"></i> List Registered
                            Patients</a>
                    </div>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/appointments/getappointment" id="appointment"><i class="fas fa-calendar-plus"></i> Appointments
                    </a>
                </li>
                {% if user.is_authenticated %}
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"
                        aria-expanded="false">
                        Welcome, {{ user.get_username }}
                    </a>
                    <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                        <a class="dropdown-item" href="{% url 'logout'%}?next={{request.path}}"><i class="fas fa-sign-out-alt"></i>
                            Logout</a>
                        <a class="dropdown-item" href="/clinic/myprofile"><i class="fas fa-user-alt"></i> My Profile</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="/appointments/myappointments"><i class="fas fa-calendar"></i> My Appointments</a>
                    </div>
                </li>
                {% else %}
                <li class="nav-item active">
                    <a class="nav-link" href="{% url 'login'%}?next={{request.path}}"><i class="fas fa-key"></i> Login
                    </a>
                </li>
                {% endif %}
            </ul>
            <form class="form-inline my-2 my-lg-0">
                <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
                <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
            </form>
        </div>
    </nav>
</header>

clinic / common_css.html:

{% load static %}
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="{% static 'clinic/css/bootstrap.css' %}">
<link rel="stylesheet" href="{% static 'appointments/css/datepicker.0.6.5.css' %}">
<link rel="stylesheet" href="{% static 'appointments/css/fontawesome.5.2.0.css' %}">
<link rel="stylesheet" href="{% static 'appointments/css/jquery-ui/jquery-ui.css' %}">
<link rel="stylesheet" href="{% static 'appointments/css/jquery-ui/jquery-ui.structure.css' %}">
<link rel="stylesheet" href="{% static 'appointments/css/jquery-ui/jquery-ui.theme.css' %}">
<link rel="stylesheet" href="{% static 'appointments/css/fullcalendar.css' %}">
<link rel="stylesheet" href="{% static 'appointments/css/calcustomcolors.css' %}?dev={{ rnd_num }}">
<link rel="stylesheet" href="{% static 'appointments/propellor/typography.css' %}">
<link rel="stylesheet" href="{% static 'appointments/propellor/materialicons.css' %}">
<link rel="stylesheet" href="{% static 'appointments/propellor/button.css' %}">
<link rel="stylesheet" href="{% static 'appointments/propellor/floating-action-button.css' %}">
<link rel="stylesheet" href="{% static 'appointments/propellor/google-icons.css' %}">
<link rel="stylesheet" href="{% static 'appointments/css/mytheme.css' %}">

clinic / common_js.html:

{% load static %}
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="{% static 'appointments/js/jquery-3.3.1.min.js' %}"></script>
<script src="{% static 'appointments/js/jquery-ui/jquery-ui.js' %}?dev={{ rnd_num }}"></script>
<script src="{% static 'appointments/js/popper.min.js' %}"></script>
<script src="{% static 'appointments/js/bootstrap.min.js' %}"></script>
<script src="{% static 'appointments/js/notify.0.4.2.js' %}"></script>
<script src="{% static 'appointments/js/datepicker.0.6.5.js' %}"></script>
<script src="{% static 'appointments/lib/moment.min.js' %}"></script>
<script src="{% static 'appointments/js/fullcalendar.js' %}"></script>
<script src="{% static 'appointments/js/search.js' %}?dev={{ rnd_num }}"></script>
<script src="{% static 'appointments/js/appointment.js' %}?dev={{ rnd_num }}"></script>

我得到的错误是:

In template /home/joel/myappointments/appointments/templates/clinic/index.1.html, error at line 60
Invalid block tag on line 60: 'else', expected 'endblock'. Did you forget to register or load this tag?

模板中是否存在明显的错误?

1 个答案:

答案 0 :(得分:2)

{% if nodoc}在第12行-您缺少%,该行应为{% if nodoc %}