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),
]
2.models.py
from django.db import models # Create your models here.
class Classes(models.Model):
title = models.CharField(max_length=)
m =models.ManyToManyField("Teachers") class Teachers(models.Model):
name = models.CharField(max_length=) class Students(models.Model):
username = models.CharField(max_length=)
age = models.IntegerField()
gender = models.BooleanField()
cs = models.ForeignKey(Classes,on_delete=models.CASCADE,)
3.get_students.html(获取学生信息)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div>
<a href="/add_students.html">添加</a>
</div>
<div>
<table border="">
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
<th>性别</th>
<th>年龄</th>
<th>班级</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{% for row in stu_list %}
<tr nid="{{ row.id }}">
<td>
{{ row.id }}
</td>
<td>
{{ row.username }}
</td>
<td>
{{ row.gender }}
</td>
<td>
{{ row.age }}
</td>
<td>
{{ row.cs.title }}
</td>
<td>
<a href="/del_students.html?nid={{ row.id }}">删除</a>
<a href="/edit_students.html?nid={{ row.id }}">编辑</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
</html>
4.add_students.html(添加学生)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h3>添加用户</h3>
<form method="POST" action="/add_students.html">
{% csrf_token %}
<p><input type="text" name="username" placeholder="用户名" /></p>
<p><input type="text" name="age" placeholder="年龄" /></p>
<p>
男:<input type="radio" name="gender" value="" />
女:<input type="radio" name="gender" value="" />
{# name=gender是为了互斥#}
</p>
<p>
<select name="cs">
{% for row in cs_list %}
<option value="{{ row.id }}">{{ row.title }}</option>
{% endfor %}
</select>
</p>
<input type="submit" value="提交">
</form> </body>
</html>
导致报错的原因:用户名和年龄的input标签少了一斜杠

Django学生管理系统添加学生时,报错Not Found: /POST的更多相关文章
- mysql中添加数据时,报错(incorrect string value:'\xf0\x9f ) 字符转换不正确
这个问题,原因是UTF-8编码有可能是两个.三个.四个字节.Emoji表情或者某些特殊字符是4个字节,而Mysql的utf8编码最多3个字节,所以数据插不进去. 在网上搜了一下解决问题的方案,我选了一 ...
- Django Admin后台添加用户时出现报错:1452
如果在使用Django Admin后台添加用户时出现报错: (1452, 'Cannot add or update a child row: a foreign key constraint fai ...
- Django 编写自定义的 404 / 500 报错界面
Django 编写自定义的 404 / 500 报错界面 1. 首先 setting.py 文件中的 debug 参数设置成 false ,不启用调试. DEBUG = False 2. 在 temp ...
- linux下, 再次遇到使用thinkphp的模板标签时,报错used undefined function \Think\Template\simplexml_load_string() 是因为没有安装 php-xml包
linux下, 使用thinkphp的模板标签,如 eq, gt, volist defined, present , empty等 标签时, 报错: used undefined function ...
- WPF加载Winform窗体时 报错:子控件不能为顶级窗体
一.wpf项目中引用WindowsFormsIntegration和System.Windows.Forms 二.Form1.Designer.cs 的 partial class Form1 设置为 ...
- python2 + selenium + eclipse 中,通过django生产数据库表的时候报错
python2 + selenium + eclipse 中,通过django生产数据库表的时候报错 解决: 1.查看自己电脑中,“开始-->控制面板-->管理工具-->服务--&g ...
- VMWare EXSi 添加新磁盘时 报错 HostStorageSystem.ComputeDiskPartitionInfo 的处理
给 VMWare EXSi 添加新磁盘时报错 : Call "HostStorageSystem.ComputeDiskPartitionInfo" for object &quo ...
- MongoDB添加仲裁节点报错replica set IDs do not match办法
背景:由于历史原因,某个MongoDB副本集只有一主一从双节点,无法满足自动故障转移要求,需要配置一个仲裁节点. 原有节点192.168.10.20:27017,192.168.10.21:27017 ...
- python测试开发django-45.xadmin添加小组件报错解决
前言 xadmin首页上有个添加小组件按钮,打开的时候会报错"render() got an unexpected keyword argument 'renderer'" 环境: ...
随机推荐
- HDU2444 :The Accomodation of Students(二分图染色+二分图匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- Qt error ------ 出现Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly
出现原因: 使用了不存在的对象 数组越界了 用 delete 释放未分配的内存空间,或者超过一次释放同个内存 比如: 顺序不能颠倒 正确: ui->setupUi(this); ui->t ...
- Java并发之同步原语
volatile: 定义:Java编程语言允许线程访问共享变量,为了确保共享变量内被准确和一致性地更新,线程应该确保通过排它锁单独获得这个变量.根据volatile的定义,volatile有锁的语义. ...
- shell编程:条件测试与比较(六)
条件测试方法综述 test条件测试的简单语法及测试 范例6-1 测试文件(在test命令中使用-f选项:文件存在且为不同文件则表达式成立) [root@adminset ~]# test -f fil ...
- jQuery图表插件Flot中文文档
转载自:http://www.itivy.com/ivy/archive/2011/6/4/jquery-flot-chinese-doc.html 最近正在使用JQuery的flot进行画图,但是这 ...
- 在windows下如何使用密钥对远程登录服务器?
在企业的生产中相信各位朋友都会使用远程登录服务器,这样即高效也非常方便,(服务器在西藏,没有远程技术,公司在北京,你只能到西藏与机器相伴,在这里我使用xshell软件),我们使用ssh 服务登录服务器 ...
- List<Hashtable>排序
hashtableList.Sort( delegate (Hashtable a, Hashtable b) { DateTime dateTime1 = (DateTime)a["ber ...
- LightOJ 1137 - Expanding Rods 基础计算几何
http://www.lightoj.com/volume_showproblem.php?problem=1137 题意:一根长度为L的杆热膨胀为L',左端点到右端点间距离不变,且膨胀后的杆的弧为圆 ...
- LightOJ 1341 - Aladdin and the Flying Carpet 基本因子分解
http://www.lightoj.com/volume_showproblem.php?problem=1341 题意:给你长方形的面积a,边最小为b,问有几种情况. 思路:对a进行素因子分解,再 ...
- web api 支持cors
1. configservice //******************* cors start *********************** var urls = Configuration[S ...