簡體   English   中英

django模板代碼未加載:“ TemplateSyntaxError:第19行“ applink”上的無效塊標記。 您是否忘記注冊或加載此標簽?”

[英]django template code not loading: “TemplateSyntaxError : Invalid block tag on line 19: 'applink'. Did you forget to register or load this tag?”

我正在使用Django 1.9.4和Python3.4構建Django應用程序。 我不斷收到錯誤:

Error during template rendering

In template /home/enlighter/workspace/ndl-question-papers-search-hub/qp_search_project/templates/base.html, error at line 19
block tag on line 19: 'applink'. Did you forget to register or load this tag?

  14      <body>
  15        <div class="navbar navbar-inverse navbar-fixed-top">
  16          <div class="container">
  17            <div class="navbar-header">
  18              <a href="http://ndl.iitkgp.ac.in/" class="navbar-brand"><img src="{% static "images/ndl-logo.png" %}" height="21" /></a>
  19              <a href="{% applink "/" %}" class="navbar-brand">NDL QP</a>
  20            </div>
  21            

這是我的項目目錄結構:

manage.py
qp_search_project
searcher
|--admin.py
|--apps.py
|--forms.py
|--static
   |--css
|--models.py, etc.
templates
|--base.html
|--searcher
   |--index.html

上面帶有"{% applink "/" %}" html代碼在base.html中,而我的searcher / index.html是:

{% extends "base.html" %}

{% block title %}
Search Question Papers
{% endblock %}

{% block content %}
blah blah blah
{% endblock %}

在我的應用程序的views.py呈現index.html頁面的方法是:

from django.shortcuts import render
from django.http import HttpResponse

from .forms import NameForm

applink = "/searcher"

def index(request):
    context_dict = {
        'applink' : applink
    }
    return render(request, 'searcher/index.html', context_dict)

我正在嘗試從上下文渲染“ applink”並將其追加/添加到其中? 換句話說,我想渲染'/searcher/'

請幫忙!

此Django項目代碼位於存儲庫中: https : //github.com/enlighter/ndl-question-papers-search-hub/tree/master/qp_search_project

要呈現上下文對象,您應該使用{{ applink }}而不是{% applink %}

在您的模板中:

替換為:

<a href="{% applink "/" %}" class="navbar-brand">NDL QP</a>

有了這個:

<a href="{{ applink }}/" class="navbar-brand">NDL QP</a>

閱讀django-docs

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM