pythondjangodjango-widget-tweaks

TemplateSyntaxError: widget_tweaks is not a valid library django


I am new to django and I am trying to trying to implement a form that uses widget-tweaks.

I did install widget tweaks (I am using Ubuntu 14.04)

sudo pip install django-widget-tweaks

My settings file looks like this:

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'core',
'addattr',
'widget_tweaks',
)

The html looks like this:

{% extends "base/theme.html" %}
{% load widget_tweaks %}
{% block main_content %}
...more code...

The class in the views and the linking in the url works perfectly fine.

But every time when I try to load the html it says:

widget_tweaks' is not a valid tag library: Template library widget_tweaks not found, tried django.templatetags.widget_tweaks,django.contrib.admin.templatetags.widget_tweaks,django.contrib.staticfiles.templatetags.widget_tweaks

Can anyone help? Thanks in advance


Solution

  • ubuntu use pip3

    step 1:


    convert
    sudo pip install django-widget-tweaks
    

    to:

    sudo pip3 install django-widget-tweaks
    

    step 2:


    add name lib in settings.py

    you can use :

    INSTALLED_APPS+=['widget-tweaks']
    

    or inside

    INSTALLED_APPS

    step 3:


    in templates use:
    {% load widget_tweaks %}
    

    test:

    in templates

    {% load widget_tweaks %}
    <!-- change input type (e.g. to HTML5) -->
    {% render_field form.search_query type="search" %}