Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

At wits end with django refusing to use widget-tweaks tags #46

Closed
SHxKM opened this issue May 20, 2017 · 4 comments
Closed

At wits end with django refusing to use widget-tweaks tags #46

SHxKM opened this issue May 20, 2017 · 4 comments

Comments

@SHxKM
Copy link

SHxKM commented May 20, 2017

So I've been troubleshooting this for many hours now, without avail.

I've pip-installed django-widget-tweaks, and included 'widget_tweaks' in my settings.py file.

I also have this in my base.html file:

{% load static %}
{% load i18n %}
{% load compress %}
{% load widget_tweaks %}

I've tried a gazillion ways to {{ field|add_class:"form-control" }} or {% render_field...%}, and each time it will throw an error along the lines of "did you forget to register this tag?

My .pug file which extends base.html:

div(class="col-lg-4 col-md-6 cold-sm-12")
                    - var da_form = form
                    H3 Bottle Form
                    //- TODO: fix fields to dynamically adjust
                    form(method="post" action=".")
                        | {% csrf_token %}
                        for field in da_form.visible_fields
                            div(class="form-group row")
                                label(class="col-lg-4 col-md-3 col-sm-6 col-form-label") {{field.label_tag}}
                                div(class="col-lg-8 col-md-3 col-sm-6")
                                 | {{ field|add_class:"form-control" }}
                        input(class="form-control")(type="submit" value="submit")

Error when using add_class:

Invalid filter: 'add_class'

Error when using render_field:

Invalid block tag on line 54: 'render_field', expected 'empty' or 'endfor'. Did you forget to register or load this tag?

Notice that while this is a .pug file, the | basically means this is treated the very same like HTML/django variable.

Things I've tried and didn't help:

  1. Uninstalling widget_tweaks and re-installing
  2. doing for field in da_form instead of for field in da_form.visible_fields
  3. Loading both in .pug file and base.html, either, and both.
  4. loading core.widget_tweaks (where core is the app where my settings.py file is, that threw an error that core.widget_tweaks isn't a registered tag)
  5. Restarting the server
@SHxKM
Copy link
Author

SHxKM commented May 20, 2017

The "solution" was very simple: We must load widget_tweaks in our template file (extending base.html isn't enough), but have to use the django built-in tag for loading it and not pypugjs's load.

@SHxKM SHxKM closed this as completed May 20, 2017
@AkilThangavel
Copy link

            <form class="form-inline my-2 my-lg-0" method="POST">{% csrf token %}                    
                <input class="form-control mr-sm-2" type="search" placeholder="To-do item" aria-label="Search" name="item">
                
                <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Add to List</button>
              </form>

what is the error in this please help

@AkilThangavel
Copy link

            <form class="form-inline my-2 my-lg-0" method="POST">{% csrf token %}                    
                <input class="form-control mr-sm-2" type="search" placeholder="To-do item" aria-label="Search" name="item">
                
                <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Add to List</button>
              </form>

what is the error in this csrf token..

@Dainwright
Copy link

@Akil1996 it should be csrf_token, there needs to be an underscore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants