< a href="https://github.com/%E5%B0%8F%E7%9A%AE%E6%B5%A9"> Fork me on GitHub

图书管理部分代码1

<!doctype html>

前端页面代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/static/bootstrap-3.3.7-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/bootstrap-3.3.7-dist/js/bootstrap.min.js">

</head>

<body>
<div class=" row" >
<div class="col-md-8 col-md-offset-2" style="text-align: center">
<h1>图书添加<small>----郭建凯亲历打造</small></h1>
</div>

<div class="alert alert-success" role="alert" style="font-size:50px;text-align: center">添加书籍</div>
<div class="clo-xs-8 col-md-offset-2">
<form action="" method="post">
{% csrf_token %}
<div class="form-group center-block" style="font-size: 50px;display: block;">
<label for="title">书籍名称</label>
<input type="text" class="form-control" id="title" placeholder="书籍名称" style="height: 100px" name="title">
</div>
<div class="form-group center-block" style="font-size: 50px;display: block;">
<label for="price">价格</label>
<input type="number" class="form-control" id="price" placeholder="价格" style="height: 100px" name="price">
</div>
<div class="form-group center-block" style="font-size: 50px;display: block;">
<label for="publication_date">出版日期</label>
<input type="date" class="form-control" id="publication_date" placeholder="出版日期" style="height: 100px;" name="publication_date">
</div>
<div class="form-group center-block" style="font-size: 50px;display: block;">
<label for="press">出版社</label>
<input type="text" class="form-control" id="press" placeholder="出版社" style="height: 100px" name="press">
</div>
<a class="btn btn-success btn-lg pull-right" href="{% url 'book' %}" role="button" style="font-size: 100px"><button type="submit">Submit</button></a>
</form>
</div>
</div>
</body>
</html>

url接口:

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^book/$', views.book,name='book'),
    url(r'^book/add/$', views.book_add,name='book_add'),
    url(r'^book/edit/(\d+)/$', views.book_edit,name='book_edit'),
    url(r'^book/del/(\d+)/$', views.book_del,name='book_del'),
    url(r'^search/1/$', views.search_1,name='search_1'),
    url(r'^search/$', views.search,name='search'),

]

view视图代码:

def book_add(request):
    print(456)
if request.method == &#39;GET&#39;:
    # return HttpResponse(&quot;ok&quot;)
    return render(request,&#39;book_add.html&#39;)

else:
    data = request.POST.dict()
    del data[&#39;csrfmiddlewaretoken&#39;]
    a = models.Book(**data)
    a.save()
    return redirect(&#39;book&#39;)

 

posted @ 2020-01-11 22:14  赌徒!  阅读(109)  评论(0编辑  收藏  举报