Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

crispy_forms_tag' is not a valid tag library

I'm trying to create a Django app using Django crispy-forms.

settings.py

CRISPY_TEMPLATE_PACK = 'bootstrap3'

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'face',    #app name
    'crispy_forms',
)

index.html

{% extends "base.html" %}
{% load crispy_forms_tag %}

{% block title %}
AuthorizedUser
{% endblock title %}

{% block content %}
    <h1>Quote of the Day</h1>
    <blockquote>{{quote}}</blockquote>
    <p>Or, hit reload if you want a new one...</p>

    <form method="POST" action="{% url  %}"  >
        {% csrf_token %}
        {{ form|crispy}}
        <input type="hidden" name="quote" value="{{quote}}" />
        <input type="hidden" name="access_token" value="{{access_token}}" />
        <input type="submit" value="Set as my status!"/>
    </form>
{% endblock content %}

When I'm running server it's raising an error

"TemplateSyntaxError at / 'crispy_forms_tag' is not a valid tag library: Template library crispy_forms_tag not found, trieddjango.templatetags.crispy_forms_tag,django.contrib.staticfiles.templatetags.crispy_forms_tag,django_facebook.templatetags.crispy_forms_tag,crispy_forms.templatetags.crispy_forms_tag".

What am I doing wrong? And how to fix it?

like image 801
Vishnu Kant Avatar asked Jul 28 '14 08:07

Vishnu Kant


3 Answers

I've gone through that error just now.

Forgot to install django-crispy-forms

pip install django-crispy-forms

and refer it in settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'crispy_forms',
]

Once that was done, the problem was solved.

like image 150
molecoder Avatar answered Oct 03 '22 00:10

molecoder


You should add Crispy Form tag in project setting .

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'crispy_forms',
]

add these crisp tag in your templates.html

    {% load crispy_forms_tags %}
      {% csrf_token %}
    {% crispy form %}
like image 44
Jeet Kumar Avatar answered Oct 03 '22 00:10

Jeet Kumar


Are you sure that the installation of Crispy forms worked ? you need to install django-crispy-forms.

Then, in your template index.html, you should use the crispy tag as following :

{% crispy name_form %} 

instead of :

{{form|crispy}}

What's more, you should use

{% load crispy_forms_tags %}

not,

{% load crispy_forms_tag %}
like image 30
Rémi P Avatar answered Oct 03 '22 02:10

Rémi P