python - Django can't find my custom template filter -
i'm trying create custom template filter in django app. i've created templatetags folder under app, added __init__.py
file , filters.py file filters, so:
import os django import template django.template.defaultfilters import stringfilter register = template.library() @register.filter @stringfilter def filename(pathname): """ returns file's name, without folder """ return os.path.basename(pathname)
when try access filter template, error "invalid filter 'filename'"
this question has been asked lot, checked following:
__init__.py
named- after opening shell
manage.py shell
can import filter so:import app.templatetags
- i can use filter django shell
- i have restarted django development server.
- i have placed breakpoint on call
template.library()
- debugger doesn't stop there.
here template (i've removed parts of it, error persists in small version, well)
<form enctype="multipart/form-data" action="{% url lab.views.new.artefact_drop_web tempfile_id=tempfile.id %}" method="post"> {% csrf_token %} <h3>file:</h3> <p>{{ tempfile.file.name|filename }}</p> <input type="submit" value="add" /> </form>
you need use {% load name_of_file_tags_are_in %}
inside template.
https://docs.djangoproject.com/en/1.5/howto/custom-template-tags/
Comments
Post a Comment