tags:

views:

26

answers:

1

I have an errror: 'run_target' is not a valid tag library: Template library run_target not found, tried django.templatetags.run_target

I don't know why it can't work, even i add 'db.templatefilters' it can't work too... Can anyone help me? thank you :)

Below is my file structure:

db/
    models.py
    templatefilters/
        __init__.py
        run_target.py
templates/
    run.html

run_target.py

from django import template
register = template.Library()

@register.simple_tag
def dictKeyLookup(the_dict, key):
       return the_dict[key]

run.html

{% extends "index.html" %}
**{% load run_target %}**
{% block content %}
<div style="margin-left:150px; margin-top:10px">
<a href="/home">Home</a> >> <b>run</b>
</div>
<form name="form" method="post">
<br>
<input type="submit" value="Delete" style="margin-left:149px; width:80px; height:30px">
<table border="1"; style="margin-left:150px; border-collapse:collapse;margin-top:10px"; cellpadding="4" borderColor=black>

{% for run in run_list %}
    <tr>
    <td>{% dictKeyLookup target_dict run.id %}</td>
    </tr>
{% endfor %}
</table>
</form>
{% endblock %}
+3  A: 

Is db in your INSTALLED_APPS setting?

If so, then it looks like the two other things you're missing are:

  • an __init__.py file in your db folder itself (you've got one in your templatefilters directory, but not its parent directory)
  • the templatefilters folder should be called templatetags (see the Code layout section of the documentation).

Incidentally, db is not a very good name for an app - call it something that more closely identifies what it does.

Dominic Rodger
thanks for you answer, i don't know the folder name 'templatetags' can't be changed, thanks again :)
Yuan