Django学生管理系统添加学生时,报错Not Found: /POST

最近在学习Django,跟着视频写了一个学生系统,主要是增删改查操作,界面丑的一匹

1.url.py

from django.contrib import admin
from django.urls import path,re_path
from app01.views import classes
from app01.views import teachers
from app01.views import students

urlpatterns = [
    path('admin/', admin.site.urls),
    re_path('get_classes.html$', classes.get_classes),
    re_path('add_classes.html$', classes.add_classes),
    re_path('update_classes.html$', classes.update_classes),
    # re_path('edit_classes.html$', classes.edit_classes),
    re_path('del_classes.html$', classes.del_classes),
    re_path('get_students.html$', students.get_students),
    re_path('add_students.html$', students.add_students),
]
View Code

 

2.models.py

from django.db import models

# Create your models here.
class Classes(models.Model):
    title = models.CharField(max_length=32)
    m =models.ManyToManyField("Teachers")


class Teachers(models.Model):
    name = models.CharField(max_length=32)


class Students(models.Model):
    username = models.CharField(max_length=32)
    age = models.IntegerField()
    gender = models.BooleanField()
    cs = models.ForeignKey(Classes,on_delete=models.CASCADE,)
View Code

 

3.get_students.html(获取学生信息)

"en">

    "UTF-8">
    Title


    
    
"1"> {% for row in stu_list %} "{{ row.id }}"> {% endfor %}
ID 姓名 性别 年龄 班级 操作
{{ row.id }} {{ row.username }} {{ row.gender }} {{ row.age }} {{ row.cs.title }} "/del_students.html?nid={{ row.id }}">删除 "/edit_students.html?nid={{ row.id }}">编辑
View Code

 

4.add_students.html(添加学生)

"en">

    "UTF-8">
    Title


添加用户

"POST" action="/add_students.html"> {% csrf_token %}

"text" name="username" placeholder="用户名" />

"text" name="age" placeholder="年龄" />

男:"radio" name="gender" value="1" /> 女:"radio" name="gender" value="0" /> {# name=gender是为了互斥#}

<select name="cs"> {% for row in cs_list %} {% endfor %} select>

"submit" value="提交">
View Code

 

导致报错的原因:用户名和年龄的input标签少了一斜杠

Django学生管理系统添加学生时,报错Not Found: /POST_第1张图片

 

转载于:https://www.cnblogs.com/liangjiongyao/p/9243764.html

你可能感兴趣的:(Django学生管理系统添加学生时,报错Not Found: /POST)