在Django中制作多选HTML表

时间:2018-11-24 10:48:04

标签: python html django

def index(request):
    pull_requestsList = Pull_Requests.objects.all()
    paginator = Paginator(pull_requestsList, 25)
    page=request.GET.get('page')
    try:
        pullrequests=paginator.page(page)
        #pullRequest_dict = {'pull_requests': pullrequest}
    except PageNotAnInteger:
        pullrequests=paginator.page(1)
    except EmptyPage:
        pullrequests=paginator.page(paginator.num_pages)

    return render(request, 'index.html', {'pullrequests': pullrequests})


{% load staticfiles %}
        <link rel="stylesheet" type="text/css" href="{% static 'css/style.css'%}">
        {% block body %}
            <div class="container" align="center" xmlns="http://www.w3.org/1999/html">
            {% block table %}
                <p><br><br><br><br></p>

                <table class="table table-bordered" border="1">
                    <tr>
                        <th>Project</th>
                        <th>Pull Request ID </th>
                        <th>Nb comments </th>
                        <th> LC added </th>
                        <th> LC deleted </th>
                        <th> Nb commits </th>
                        <th> Nb changed fies </th>
                        <th> Closed status </th>
                        <th> Reputation </th>
                        <th> Label </th>
                    </tr>
                    {% for field in pullrequests %}
                        <tr>
                            <td>{{ field.pr_project  }}</td>
                            <td>{{ field.pr_id }} </td>
                            <td>{{ field.nd_comments }} </td>
                            <td>{{ field.nb_added_lines_code }}</td>
                            <td>{{ field.nb_deleted_lines_code }}</td>
                            <td>{{ field.nb_commits }}</td>
                            <td>{{ field.nb_changed_fies }}</td>
                            <td>{{ field.Closed_status }}</td>
                            <td>{{ field.reputation }}</td>
                            <td>{{ field.Label }}</td>
                        </tr>
                    {% endfor %}
                </table>

            {% endblock table %}
            </div>
        {% endblock %}

        <div class="pagination" align="center">
            <span class="step-links">
                {% if pullrequests.has_previous %}
                    <a href="?page={{ pullrequests.previous_page_number }}">Previous</a>
                {% endif %}

                <span class="current">
                    Page {{ pullrequests.number }} of {{ pullrequests.paginator.num_pages }}.
                </span>

                {% if pullrequests.has_next %}
                    <a href="?page={{ pullrequests.next_page_number }}">Next</a>
                {% endif %}
            </span>
        </div>

我希望用户可以通过复选框选择HTML表中的多行,并将所选行加载到另一个网页index2文件中。但是我不知道该怎么做。现在,我可以在索引页面上显示我的数据,并且可以正常工作。上面是视图和索引文件,但是我想在每行中添加一个复选框,该复选框允许用户选择他或她想要修改的行。 感谢您的帮助。

0 个答案:

没有答案