book_manage数据库的book中插入数据
base.html
{% load static %}
add_book_1.html
{% extends ‘base.html’ %}
{% block content %}
| 书名: | |
| 作者: | |
{% endblock %}
settings.py中禁用csrf
‘django.middleware.csrf.CsrfViewMiddleware’,
urls.py
path(‘index_1/’,views.index_1,name=‘index_1’),
path(‘add_book_1/’,views.add_book_1,name=‘add_book_1’),
views.py
def add_book_1(request):
if request.method == ‘GET’:
print(“aaaaaaa”)
return render(request,‘add_book_1.html’)
else:
print(“bbbbbbbbbbbbb”)
name = request.POST.get(‘name’)
author = request.POST.get(‘author’)
cursor = get_corsor()
cursor.execute(“insert into book(id,name,author) values(null,’%s’,’%s’)” %(name,author))
return redirect(reverse(‘index_1’))