jazzband / django-floppyforms

Full control of form rendering in the templates.
http://django-floppyforms.readthedocs.org/
Other
839 stars 145 forks source link

not fork in inclusion tag #111

Closed artofhuman closed 10 years ago

artofhuman commented 10 years ago
# feedback/forms.py
import floppyforms as forms

class FeedbackForm(forms.ModelForm):
    class Meta:
        model = Feedback

# feedback/templatetags/feedback_tags.p
@register.inclusion_tag('feedback/_feedback_form.html', takes_context=True)
def feedback_form(context):
    request = context['request']
    form = FeedbackForm(request.POST, request.FILES)
    return {'form': form}

# _feedback_form.html
{% load floppyforms %}
{% form form using %}
    {% formfield form.comment with placeholder="test" %}
{% endform %}

Got error

VariableDoesNotExist at /
Failed lookup for key [comment] in 'None'

But if render as

    {{ form.comment }}

Thats work

gregmuellegger commented 10 years ago

Hi, I put this into a templatetags/foo.py:

# -*- coding: utf-8 -*-
import floppyforms as forms
from django import template
from django.db import models

class Feedback(models.Model):
    comment = models.CharField(max_length=50)

class FeedbackForm(forms.ModelForm):
    class Meta:
        model = Feedback

register = template.Library()

@register.inclusion_tag('_feedback_form.html', takes_context=True)
def feedback_form(context):
    form = FeedbackForm({})
    return {'form': form}

And then called a template with the following content:

    {% load foo %}
    {% feedback_form %}

The result I get is this: <input id="id_comment" maxlength="50" name="comment" type="text" />

So everything seem to work fine for me. Sorry that I cannot reproduce, maybe you have more information that I can take into account for further investigations.