包括带模板标签的bootstrap模态模板

时间:2016-02-15 22:28:51

标签: django twitter-bootstrap django-forms django-templates

我正在尝试创建一个可以包含在我的html文件中的引导模式,因为我将表单放入模态中并且我不想每次都创建一个新的mdoal。

除了尝试包含表单外,它工作正常。这当然是重要的部分。我怎样才能在模板标签中包含模板上下文变量?

modal_base

 {% load crispy_forms_tags %}
<div id="{{ modal_form_id }}" class="modal fade" ariahidden="True">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <a class="close" data-dismiss="modal">X</a>
                <h1 style="text-align:center;">
                    {{ modal_form_title }}
                </h1>
            </div>
            <div class="modal-body">
                <form method="{{modal_form_method|default:'POST'}}" action="{{modal_form_action}}">
                    {% csrf_token %}
                    {{ form|crispy }}
                    <input class="btn btn-primary" type="submit" value="Create"/>
                </form>
            </div>
            <div class="modal-footer">
                <a href="#" class="btn btn-danger" data-dismiss="modal">
                    Cancel
                </a>
            </div>
        </div>
    </div>
</div>  

示例包含在某些html文件中:

 {% include 'modal_form.html' with modal_form_id="new-category" modal_form_title="Create a New Category" modal_form_method="POST" modal_form_action="/home/" form={{category_form}} %}

form = {{category_form}}是个问题。有办法解决这个问题吗? 模态渲染精细,打开关闭等我不能以表格

传递

1 个答案:

答案 0 :(得分:4)

你很亲密!唯一缺少的是你不需要花括号将它包含在include标签

SYSCALL_DEFINE6(splice, int, fd_in, loff_t __user *, off_in,
        int, fd_out, loff_t __user *, off_out,
        size_t, len, unsigned int, flags)
{
    long error;
    struct file *in, *out;
    int fput_in, fput_out;

    if (unlikely(!len))
        return 0;

    error = -EBADF;
    in = fget_light(fd_in, &fput_in);
    if (in) {
        if (in->f_mode & FMODE_READ) {
            out = fget_light(fd_out, &fput_out);
            if (out) {
                if (out->f_mode & FMODE_WRITE)
                    error = do_splice(in, off_in,
                              out, off_out,
                              len, flags);
                fput_light(out, fput_out);
            }
        }

        fput_light(in, fput_in);
    }

    return error;
}

static long do_splice(struct file *in, loff_t __user *off_in,
              struct file *out, loff_t __user *off_out,
              size_t len, unsigned int flags)
{
    struct pipe_inode_info *ipipe;
    struct pipe_inode_info *opipe;
    loff_t offset, *off;
    long ret;

    ipipe = get_pipe_info(in);
    opipe = get_pipe_info(out);

    if (ipipe && opipe) {
        if (off_in || off_out)
            return -ESPIPE;

        if (!(in->f_mode & FMODE_READ))
            return -EBADF;

        if (!(out->f_mode & FMODE_WRITE))
            return -EBADF;

        /* Splicing to self would be fun, but... */
        if (ipipe == opipe)
            return -EINVAL;

        return splice_pipe_to_pipe(ipipe, opipe, len, flags);
    }

    if (ipipe) {
        if (off_in)
            return -ESPIPE;
        if (off_out) {
            if (!(out->f_mode & FMODE_PWRITE))
                return -EINVAL;
            if (copy_from_user(&offset, off_out, sizeof(loff_t)))
                return -EFAULT;
            off = &offset;
        } else
            off = &out->f_pos;

        ret = do_splice_from(ipipe, out, off, len, flags);

        if (off_out && copy_to_user(off_out, off, sizeof(loff_t)))
            ret = -EFAULT;

        return ret;
    }

    if (opipe) {
        if (off_out)
            return -ESPIPE;
        if (off_in) {
            if (!(in->f_mode & FMODE_PREAD))
                return -EINVAL;
            if (copy_from_user(&offset, off_in, sizeof(loff_t)))
                return -EFAULT;
            off = &offset;
        } else
            off = &in->f_pos;

        ret = do_splice_to(in, off, opipe, len, flags);

        if (off_in && copy_to_user(off_in, off, sizeof(loff_t)))
            ret = -EFAULT;

        return ret;
    }

    return -EINVAL;
}