对输入框POST请求的返回值一直是NONE,不论在INPUT框中输入什么,“title”和"price"的值一直是none,而格式为date的"publish_date"正常。
执行结果如下:
[20/Aug/2021 16:46:48] "POST /book/edit/ HTTP/1.1" 302 0
None
None
2021-08-01
下面贴源代码
views.py文件
def book_edit(request):
if (request.method == 'POST'):
title = request.POST.get("title")
price = request.POST.get("price")
publish_date = request.POST.get("publish_date")
print(price)
print(title)
print(publish_date)
return redirect('book_list')
return render(request, 'book_edit.html')
book_edit.html文件中
{% extends 'home.html' %}
{% block content %}
<h3 class="text-center">编辑图书信息</h3>
<form action="{% url 'book_edit' %}" method="POST">
<p>著作名:<input type="text",name="title" class="form-control" ></p>
<p>价格:<input type="text",name="price" class="form-control" ></p>
<p>出版社:<input type="text",name="publish" class="form-control" ></p>
<p>出版日期:<input type="date" name="publish_date" class="form-control"></p>
<input type="submit" value="修改" class="btn btn-primary btn-block">
</form>
{% endblock content %}
book_list.html部分
<td>
<a href="{% url 'book_edit' book_obj.pk %}" class="btn btn-primary btn-xs">编辑</a>
<a href="{% url 'book_delete' book_obj.pk %}" class="btn btn-danger btn-xs">删除</a>
</td>
url.py
urlpatterns = [
path('admin/', admin.site.urls),
#首页
path(r'',views.home, name='home'),
#图书的展示页
path(r'book/list/', views.book_list, name='book_list'),
#书籍的添加
path(r'book/add/', views.book_add, name='book_add'),
#书籍的编辑 匹配主键值快速得到要处理的数据
path(r'book/edit/', views.book_edit, name='book_edit'),
path(r'book/delete/', views.book_delete, name='book_delete')
]