Search code examples
djangodjango-1.10

Django 1.10 TemplateSyntaxError 'future' is not a registered tag library


I am using Django 1.10 and have this library installed 'nested_inline. I really need this lib however when I load the admin page it gives me the following error.

TemplateSyntaxError at /masterproducts/product/add/
'future' is not a registered tag library. Must be one of:
admin_list
admin_modify....

Also the stacktrace is as follows

{% load i18n admin_static admin_modify %}
{% load cycle from future %}
<div class="inline-group{% if recursive_formset %} 
{{ recursive_formset.formset.prefix|default:"Root" }}
-nested-inline{% if prev_prefix %} {{ prev_prefix }}
-{{ loopCounter }}-nested-inline{% endif %} 
nested-inline{% endif %}" id="{{ inline_admin_formset.formset.prefix }}-group">
    {% with recursive_formset=inline_admin_formset stacked_template='admin/edit_inline/stacked-nested.html' tabular_template='admin/edit_inline/tabular-nested.html'%}
      <div class="tabular inline-related {% if forloop.last %}last-related{% endif %}" id="{{ recursive_formset.formset.prefix }}">
    {{ recursive_formset.formset.management_form }}
    <fieldset class="module">
       <h2>{{ recursive_formset.opts.verbose_name_plural|capfirst }}</h2>
       {{ recursive_formset.formset.non_form_errors }}
       <table>
         <thead><tr>
         {% for field in recursive_formset.fields %}

Solution

  • Ok fine got it. I just followed the answer on this thread https://github.com/iambrandontaylor/django-admin-sortable/issues/151 Below is the solution

    # templatetags/future.py
    from django.template import Library
    from django.template.defaulttags import cycle as cycle_original
    
    register = Library()
    
    @register.tag
    def cycle(*args, **kwargs):
        ''' A stub to get SortableTabularInline to work '''
        return cycle_original(*args, **kwargs)
    

    I couldn't understand what exactly to do with this as I rarely use templates. Apparently your supposed to create a directory called templatetags in your app folder and then add the future.py file to it with the code above. For more help on where to place the templatetags folder refer this https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#code-layout