django AttributeError:'str'对象没有属性'field'

时间:2017-04-19 19:15:08

标签: ajax django

我在使用django提交ajax请求时遇到此错误。 有趣的是,如果我在调试器命中它时可以手动执行这些命令。

这是views.py

def lhr_search_custodians(request):
print request
print request.GET
print "blah"
# pdb.set_trace()
if request.method == 'GET':
    search_text = request.GET.get('search_text')
else:
    search_text = ''
custodians = Person.objects.filter(last_name__contains=search_text)
context = {'custodians': custodians}
return render(request, 'corpsec/legalholdrequests/create.html', context)

这是javascript query.js

$(function () {
  $('#custodian_search').keyup(function (){
    console.log("search fired!!!");
    $.ajax({
      url: "new/search_custodians",
      type: "GET",
      data: {
        'search_text' : $('#custodian_search').val(),
        'csrfmiddlewaretoken' : $("input[name=csrfmiddlewaretoken]").val()
      },
      success : searchSuccess,
      dataType: 'html',

      error: function(xhr, errmsg, err) {
        $('#results');
      }
    });
  });
});

function searchSuccess(data, textStatus, jqXHR) {
  $('$search_results').html(data);
}

这是模板create.html

{% extends "blackbox/show.html" %}
{% load static from staticfiles %}
{% load formtags %}

{% block title %}
  New Legal Hold Request | {{ block.super }}
{% endblock title %}

{% block javascript %}
  {{ block.super }}
{% endblock javascript %}

{% block show_header_title %}
<h4>
  New Legal Hold Request
</h4>
{% endblock show_header_title %}

{% block tab_menu %}
<li class="tab">
  <a id="id_modal_matter"
     href="#matter">
    Matter
  </a>
</li>
<li class="tab">
  <a id="id_modal_custodians"
     href="#custodians">
    Custodians
  </a>
</li>
<li class="tab">
  <a id="id_modal_electronic_databases"
     href="#databases">
    Electronic Databases
  </a>
</li>
<li class="tab">
  <a id="id_modal_collection"
     href="#collection">
    Collection
  </a>
</li>
{% endblock tab_menu %}

{% block tab_content %}
<form action="/corpsec/legalholdrequests/new"
      role="form"
      method="post">
  <span id="csrfmiddlewaretoken">{% csrf_token %}</span>

  {% if form.errors %}
  <div class="alert alert-dismissable alert-danger">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Error.</strong> Please correct the following errors:
    <small>{{ form.errors }}</small>
  </div>
  {% endif %}

  <div class="row">
    <div class="col s12">
      <button id="id_form_submit"
              type="submit"
              class="btn right">
        Submit
      </button>
    </div>
  </div>

  <div class="row">
    <div id="matter" class="col s12">
      <div class="row">
        <div class="col s12 m8 offset-m2">
          <div class="card">
            <div class="card-content">
              {{ form.matter_name|bsf_field }}<br/>
              {{ form.matter_number|bsf_field }}<br/>
              {{ form.matter_category|bsf_field }}<br/>
              {{ form.priority_rating|bsf_field }}<br/>
              {{ form.preservation|bsf_field }}<br/>
              {{ form.issue_start|bsf_field }}<br/>
              {{ form.issue_stop|bsf_field }}<br/>
              {{ form.market_area|bsf_field }}<br/>
              {{ form.attorney|bsf_field }}<br/>
              {{ form.paralegal|bsf_field }}<br/>
              {{ form.risk_manager|bsf_field }}<br/>
              {{ form.category|bsf_field }}<br/>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div id="custodians" class="col s12">
      <div class="row">
        <!-- search card -->
        <div class="col s12 m3">
          <div class="card">
            <div class="card-content">
              <span class='card-title'>Search Custodians</span>
              <script src="{% static 'js/ldap-lookup.js' %}" type="text/javascript"></script>
              <script src="{% static 'js/custodian_query.js' %}" type="text/javascript"></script>
              {% csrf_token %}
                <input type="text" id='custodian_search' name="search">
            </div>
          </div>
        </div>

        <!-- results section  placeholder for now-->
        <div class="col s12 m6">
          <div class="card">
            <div class="card-content">
              <span class="card-title"> Results</span>
              <ul id="search_results">


              </ul>
            </div>
          </div>
        </div>

        <!-- action section -->
        <div class="col s12 m3">
          <div class="card">
            <div class="card-content">
              <span class="card-title">Action</span>
            </div>
          </div>

        </div>

      </div>
    </div>

    <div id="databases" class="col s12">
      <div class="row" class='database_1'>
        <div class="col s12 m8 offset-m2">
          <div class="card">
            <div class="card-content">
                <div class="row">
                  {{ database_and_criteria_1.database|bsf_field }}<br/>
                  {{ database_and_criteria_1.criteria|bsf_field }}<br/>
                </div>
            </div>
            <div class="card-action">
              <button class='btn waves-effect waves-light' id='show_next_button' type="button" name="button">Add Database and Criteria</button>
            </div>
          </div>
        </div>
      </div>
      <div class="row" id='database_2' style="display: none;">
        <div class="col s12 m8 offset-m2">
          <div class="card">
            <div class="card-content">
                <div class="row">
                  {{ database_and_criteria_2.database|bsf_field }}<br/>
                  {{ database_and_criteria_2.criteria|bsf_field }}<br/>
                </div>
            </div>
            <div class="card-action">
              <button class='btn waves-effect waves-light' id='show_next_button_2' type="button" name="button">Add Database and Criteria</button>
              <button class='btn waves-effect waves-light red' id='remove_db_criteria_2' type="button" name="button">Remove</button>
            </div>
          </div>
        </div>
      </div>
      <div class="row" id='database_3' style="display: none;">
        <div class="col s12 m8 offset-m2">
          <div class="card">
            <div class="card-content">
                <div class="row">
                  {{ database_and_criteria_3.database|bsf_field }}<br/>
                  {{ database_and_criteria_3.criteria|bsf_field }}<br/>
                </div>
            </div>
            <div class="card-action">
              <button class='btn waves-effect waves-light red' id='remove_db_criteria_3' type="button" name="button">Remove</button>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div id="collection" class="col s12">
      <div class="row">
        <div class="col s12 m8 offset-m2">
          <div class="card">
            <div class="card-content">
              <h4>Files<br/></h4>

              {{ collection_form.email|bsf_field }}<br/>
              {{ collection_form.netshare|bsf_field }}<br/>
              {{ collection_form.computer_data|bsf_field }}<br/>
              {{ collection_form.group_shares|bsf_field }}<br/>
              {{ collection_form.pst_files|bsf_field }}<br/>
              {{ collection_form.mobile_device|bsf_field }}<br/>
              {{ collection_form.drive_cam_event_number|bsf_field }}<br/>

              {{ collection_form.other_data_instructions|bsf_field }}<br/>

              <h4>Processing</h4><br/>

              {{ collection_form.processing_deadline|bsf_field }}<br/>
              {{ collection_form.emails_attachments|bsf_field }}<br/>
              {{ collection_form.everything|bsf_field }}<br/>
              {{ collection_form.dedupe_matter|bsf_field }}<br/>
              {{ collection_form.dedupe_custodian|bsf_field }}<br/>
              {{ collection_form.keywords|bsf_field }}<br/>
              {{ collection_form.archive_start|bsf_field }}<br/>
              {{ collection_form.archive_stop|bsf_field }}<br/>

              {{ collection_form.review_platform_external|bsf_field }}<br/>
              {{ collection_form.delivery_instructions|bsf_field }}<br/>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</form>

<script type="text/javascript">
  $('#show_next_button').click(function() {
    document.getElementById('database_2').style.display = 'block';
  });
  $('#show_next_button_2').click(function() {
    document.getElementById('database_3').style.display = 'block';
  });
  $('#remove_db_criteria_2').click(function() {
    document.getElementById('database_2').style.display = 'none';
  });
  $('#remove_db_criteria_3').click(function() {
    document.getElementById('database_3').style.display = 'none';
  });
</script>
{% endblock tab_content %}

0 个答案:

没有答案