在我的Django项目中,我正在尝试通过点击html按钮执行python方法

当我点击我的studentUpdate.html文件的编辑按钮时,我   正在收到以下错误:-

/ studentUpdate /处的NoReverseMatch 反向查找“ update_student”,未找到任何参数。尝试了1个模式:['update_student /(\ d +)/ $']

谁来帮帮我。

>这是我的studentUpdate.html

{% extends 'app.html' %}

{% block body %}
    <div>


        <div class="alert alert-info">All Students</div>





        <button id="show_book" type="button"  class="btn btn-success"> 
        <span class="glyphicon glyphicon-circle-arrow-left">
        </span> Back
        </button>


   <div id="edit_form"></div>

        <div id="book_form" > 
            <div class="col-lg-3"></div>
            <div class="col-lg-6">
                <form id="form" method="POST" action="{% url 'students' %}">

                    {% csrf_token %}

                        <div class="form-group">
                        <label >Student ID:</label>
                        <input type="text" name="sid" required="required" class="form-control"/> 
                    </div>
                    <div class="form-group">
                        <label>First name:</label>
                        <input type="text" name="firstname" class="form-control"/>
                    </div>
                    <div class="form-group"> 
                        <label>Last name:</label>
                        <input type="text" name="lastname" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Department:</label>
                        <input type="text" name="department" class="form-control" required="required"/>
                    </div>
                    <div class="form-group">
                        <label>Section:</label>
                        <input type="text" name="section" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Year:</label>
                        <input type="text" name="year" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <button name="save_book" id="save_book" type="submit" class="btn btn-primary" href="{% url 'update_student' %}"><span
                                class="glyphicon glyphicon-save"></span>
                            Update

                        </button>
                    </div>
                </form>
            </div>
            </div>
        </div>



{% endblock %}


{% block scripts %}
    <script>
        $(document).ready(function () 
        {
            $('#table').DataTable();
        });
        $(document).ready(function () {
            $('#add_book').click(function () {
                $(this).hide();
                $('#show_book').show();
                $('#book_table').slideUp();
                $('#book_form').slideDown();
                $('#show_book').click(function () {
                    $(this).hide();
                    $('#add_book').show();
                    $('#book_table').slideDown();
                    $('#book_form').slideUp();
                });
            });
        });

        $('.editButton').on('click', function () {
            var id = $(this).attr('data-id');

            $.ajax({
                url: 'http://localhost:8000/edit_book/' + id,
                method: 'GET'
            }).success(function (response) {
                {#                alert(response.title);#}
                $('#form')
                    .find('[name="title"]').val(response.title).end()
                    .find('[name="description"]').val(response.description).end()
                    .find('[name="author"]').val(response.author).end()
                    .find('[name="quantity"]').val(response.quantity).end();
                document.getElementById('save_book').innerText = 'Update';
                $(this).hide();
                $('#show_book').show();
                $('#book_table').slideUp();
                $('#book_form').slideDown();
                $('#add_book').hide();
                $('#show_book').click(function () {
                    $(this).hide();
                    document.getElementById('form').reset();
                    $('#add_book').show();
                    $('#book_table').slideDown();
                    $('#book_form').slideUp();
                });
            });
        });
    </script>
{% endblock %}

>这是我的Url.py文件

from django.conf.urls import url, include
from . import views
from django.urls import path, re_path

urlpatterns = [
    url(r'^index$', views.index),
    url(r'^books$', views.books, name="books"),
    url(r'^categories$', views.categories, name="categories"),
    url(r'^students$', views.students, name="students"),
    url(r'^returning$', views.returning, name="returning"),
    url(r'^borrow$', views.borrow, name="borrow"),
    url(r'^edit_book/(\d+)/$', views.edit_book, name="edit_book"),
    url(r'^edit_category/(\d+)/$', views.edit_category, name="edit_category"),
    url(r'^delete_book/(\d+)/$', views.delete_book, name="delete_book"),
    url(r'^delete_category/(\d+)/$', views.delete_category, name="delete_category"),
    url(r'^delete_student/(\d+)/$', views.delete_student, name="delete_student"),
    #url(r'^studentUpdate/(\d+)/$', views.studentUpdate, name="studentUpdate"),
    path('studentUpdate/', views.studentUpdate), 
    url(r'^update_student/(\d+)/$', views.update_student, name="update_student"),
]
这是我的views.py文件
from django.shortcuts import render, redirect
from django.http import JsonResponse
from django.db.models import Sum
from datetime import date
from datetime import datetime
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
# Create your views here.
from library.models import Book, Category, Student, Borrow
import playsound
from django.template import loader 




def index(request):
    return render(request, "index.html", {})


def categories(request):
    if request.method == "POST":
        title = request.POST['title']

        Category(title=title).save()
        return redirect('/categories')
    categories = Category.objects.all()
    return render(request, "category.html", {"categories": categories})


def delete_category(request, id):
    category = Category.objects.filter(id=id)
    category.delete()
    return redirect('/categories')


def edit_category(request, id):
    category = Category.objects.filter(id=id).get()
    return JsonResponse({'title': category.title})


def books(request):
    if request.method == "POST":
        title = request.POST['title']
        author = request.POST['author']
        cat = Category.objects.get(id=int(request.POST['category_id']))
        description = request.POST['description']
        available = int(request.POST['quantity'])

        book = Book(title=title, author=author, description=description, available=available)
        book.save()
        if book.categories.add(cat):
            return redirect('/books')
    books = Book.objects.all()
    categories = Category.objects.all()
    return render(request, "books.html", {"books": books, "categories": categories})


def edit_book(request, id):
    book = Book.objects.filter(id=id).get()
    return JsonResponse(
        {'title': book.title, 'author': book.author, 'description': book.description, 'available': book.available})


def delete_book(request, id):
    book = Book.objects.filter(id=id).get()
    book.delete()
    return redirect("/books")




def students(request):
    if request.method == "POST":
        sid = request.POST["sid"]
        firstname = request.POST["firstname"]
        lastname = request.POST["lastname"]
        department = request.POST["department"]
        section = request.POST["section"]
        year = request.POST["year"]

        student = Student(student_id=sid, firstname=firstname, lastname=lastname, department=department,
                          section=section, year=year)
        student.save()
        return redirect("/students")
    students = Student.objects.all()
    return render(request, "students.html", {"students": students})



def borrow(request):
    if request.method == "POST":
        student_id = request.POST['student_id']
        student = Student.objects.get(id=student_id)
        status = "Borrowed"
        books_id = request.POST.getlist('selector')
        for book_id in books_id:
            book = Book.objects.get(id=book_id)
            b = Borrow(qty=1, status=status)
            b.save()
            b.student.add(student)
            b.book.add(book)
            return redirect("/borrow")
    students = Student.objects.all()
    books = Book.objects.all()
    datas = []
    for book in books:
        left = Borrow.objects.filter(status="Borrowed", book__title=book.title).aggregate(Sum('qty'))
        if left['qty__sum'] is None:
            l = 0
        else:
            l = int(left['qty__sum'])
        datas.append(book.available - l)
    return render(request, "borrow.html", {"datas": zip(books, datas), "students": students})



def delete_student(request, id):

    student = Student.objects.filter(id=id).get()
    student.delete()
    return redirect('/students')





def returning(request):
    if request.method == "POST":
        b_id = int(request.POST["borrow_id"])
        borrow = Borrow.objects.get(id=b_id)
        borrow.date = datetime.now()
        borrow.status = "Returned"
        borrow.save()
        return redirect('/returning')
    borrows = Borrow.objects.all()
    return render(request, "return.html", {"borrows": borrows})

def studentUpdate(request):
    template = loader.get_template('studentUpdate.html')
    return HttpResponse(template.render()) 


def update_student(request,id):
    return redirect('/students')
评论