2

template.html

<tr id="head-{{ report_person.report_person.id}}">
   <td style="width:150px;"><input type="button" name="delete"  class="delete_icon" value="{{ report_person.report_person.id}}"/>
  {{report_person.report_person.name }}</td>
<td> {{report_person.info.first_aid}}{{report_person.info.first_aid.label}}</td>
<td>{{report_person.info.sick_bay}}{{report_person.info.sick_bay.label}}</td></tr>

urls.py

(r'^who/$', 'new_report'),

ビュー.py

def method(request):

    if request.method == 'POST':
        form = ReportPersonForm(request.POST)
        if 'delete_id' in request.POST: #To delete added names
            ReportPerson.objects.filter(id=request.POST['delete_id']).delete()
            Actions.objects.filter(id=request.POST['delete_id']).delete()
            InjuredLocation.objects.filter(id=request.POST['delete_id']).delete()
    return render

追加されたデータを削除するためのカスタム確認ポップアップ。

<div class="delete_confirm" style="display:none">
    <form  method="post" action="." id="{{ report_person.report_person.id}}">
        {% csrf_token %}
        <h2> Are you sure</h2>
        <br />             
        <div style="width:180px;float:right;margin:20px 5px 0 10px">
            <button type="button" name="delete"  class="delete_icon1" value="{{ report_person.report_person.id}}" />Delete</button>
            <button style="margin-right:10px;" type="button" class="close" name="cancel" class="forward backicon">
                <img src="{{ STATIC_URL }}images/button-icon-ir-back.png" width="12" height="17" alt="" />
            Cancel</button>
        </div>
    </form>
</div>

JavaScript:

$('.delete_icon1').click(function() {
        var csrf_token = $("#csrf_token").val();
        var id = $(this).attr('value');
        $.ajax({ // create an AJAX call...
            data:{
                csrfmiddlewaretoken: csrf_token,
                delete_id:id
            },
            type:'POST',
            url: '/report/who/', // the file to call
            cache:false,
            success: function() { // on success..
                window.location.href = window.location;
            }
        });
        return false;
    });

delete_icon以前は、正常に動作していたクラスをクリックして削除機能を実装しました。削除前に削除確認ポップアップ ボックスを追加しました。ポップアップが表示されますが、削除ボタンをクリックしても削除できvalue="{{ report_person.report_person.id}}"ません。削除するIDです。削除をクリックすると、このエラーが発生します

"ValueError at /report/who/
invalid literal for int() with base 10: ''"

value="{{ report_person.report_person.id}}"FF コンソールで id ( ) を html からテンプレートに渡す方法を知りたいです。

4

0 に答える 0