django表单无法从继承的模板访问

时间:2014-06-01 18:41:15

标签: django forms inheritance django-templates

我有一个second-base.html,它是user-image.html的父级 当我加载second-base.html时,我传递了一些表单,所有表单都可以访问,而且每件事情都可以。但当我链接到socond-base.html的孩子user-image.html时,我无法访问表单。

如果有人能帮助我

这是我的view.py

def dashboard(request):
context = RequestContext(request)
if request.method == 'GET':
    questioner_form = QuestionerForm()
    return render_to_response('second-level-base.html', locals(), context)

这是我的second-base.html

{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<title> {% block title %}{% endblock %}</title>
{% block head %} {% endblock head%}
</head>
<body>
 <div class="modal fade " id="questionerModal" tabindex="-1" role="dialog"      aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog ">
<div class="modal-content">
  <div class="modal-header" >
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>        
  </div>
  <div class="modal-body">
    <form class="form col-md-12 center-block" id="questionerForm"  role="form"   method="post" enctype="multipart/form-data" action="{% url 'Questioner' %}">
        {% csrf_token %}
       <div class="form-group">
        {{questioner_form.as_p}}           
       </div>
    </form>
   </div>

  </div>
 </div>

这是我的inrinted userimage.html的一部分,需要访问传递给它的父母的表格(second-base.html)

 {% extends 'second-level-base.html' %}
 {% load static %}
 {% block title %} User Image {% endblock %}
 {% block body %}
 {{questioner_form.as_p}}
 {% endblock %}
 </body>
 </html>

1 个答案:

答案 0 :(得分:1)

https://docs.djangoproject.com/en/dev/topics/forms/#reusable-form-templates我可以看到您必须使用includesecond-base.html模板的表单提供给userimage.html