后台完了现在来看前端,前端用了一个bootstrap框架,看起来能好看点
先看一下文件结构:在djapp里创建了两个文件夹templates和static
templates里面是要显示的页面,static里面是页面的图片、css、js
再来配置settings.py,告诉djapp静态文件的根目录
STATIC_URL = '/static/' MEDIA_PATH = './image/' #图片路径基础模板
{% load staticfiles %} <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>{% block title %}{% endblock %}</title> <link rel="stylesheet" type="text/css" href="/static/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="/static/css/bootstrap-theme.min.css"> <link rel="stylesheet" type="text/css" href="/static/css/base.css"> <script type="text/javascript" src="/static/js/jquery.min.js"></script> <script type="text/javascript" src="/static/js/bootstrap.min.js"></script> <!--[if lt IE 9]> <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script> <![endif]--> </head> <body> <!--Here is the navbar--> <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse-basepage"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div> <div class="collapse navbar-collapse" id="navbar-collapse-basepage"> <ul class="nav navbar-nav"> <li id="homepage"><a href="/">主页</a></li> <li id="viewbook"><a href="/viewroom/">查看</a></li> </ul> <ul class="nav navbar-nav navbar-right"> {% if user %} <!--user是后台数据,判断循环语句都要包在{% %}里,而一般只显示的数据在{{}}里--> <li><p class="navbar-text">欢迎你 <span id="base_name">{{ user }}</span></p></li> <li><a href="/myorder/">查看订单</a></li> <li><a href="/logout/">注销</a></li> {% else %} <li><a href="/regist/">注册</a></li> <li><a href="/login/">登录</a></li> {% endif %} </ul> </div> </div> </nav> <!-- /nav --> <!-- header --> <header class="jumbotron subhead" id="header-base"> <div class="container"> <h1>会议室预约系统</h1> </div> </header> <!-- /.header --> <!-- main part --> {% block content %}{% endblock %} <!-- /.main --> <!-- footer --> <footer class="footer" role="contentinfo"> <hr> <div class="container"> <p class="text-center">Copyright © LFL&ZMD</p> <h5 class="text-center"> Thanks For Duan Yi </h5> </div> </footer> <!-- /.footer--> <script type="text/javascript"> var act = document.getElementById("{{ active_menu }}"); act.setAttribute("class","active"); </script> </body> </html>主页
{% extends "base.html" %} {% load staticfiles %} {% block title %}会议室预约{% endblock %} {% block content %} <div class="container"> <div class="row"> <div class="col-md-8 col-md-offset-2 well"> <h2>欢迎访问会议室预约平台!</h2> </div> </div> </div> {% endblock %}
登录界面
{% extends "base.html" %} {% load staticfiles %} {% block title %}登陆{% endblock %} {% block content %} <div class="container"> <div class="row"> <div class="col-md-6 col-md-offset-3 col-sm-10 col-sm-offset-1"> {% if status == 'not_exist_or_passwd_err' %} <div class="well"> <h2 class="text-danger text-center">用户不存在或密码错误</h2> </div> {% endif %} <form method="POST" role="form" class="form-horizontal"> {% csrf_token %} <h1 class="form-signin-heading text-center">请登陆</h1> <div class="form-group"> <label for="id_user_name" class="col-md-3 control-label">用户名:</label> <div class="col-md-9"> <input type="text" class="form-control" id="id_user_name" required name="username" autofocus> </div> </div> <div class="form-group"> <label for="id_passwd" class="col-md-3 control-label">密码:</label> <div class="col-md-9"> <input type="password" class="form-control" required name="passwd" id="id_passwd"> </div> </div> <div class="form-group"> <div class="col-md-4 col-md-offset-4"> <button class="btn btn btn-primary btn-block" type="submit">登陆</button> </div> </div> </form> </div> </div> </div> {% endblock %}注册
{% extends "base.html" %} {% load staticfiles %} {% block title %}注册{% endblock %} {% block content %} <div class="container"> <div class="row"> <div class="col-md-6 col-md-offset-3 col-sm-10 col-sm-offset-1"> {% if status == 'success' %} <div class="well"> <h2 class="text-success text-center">注册成功!</h2> </div> {% elif status == 're_err' %} <div class="well"> <h2 class="text-warning text-center">密码重复错误</h2> </div> {% elif status == 'user_exist' %} <div class="well"> <h2 class="text-danger text-center">用户已经存在</h2> </div> {% endif %} <form method="POST" role="form" class="form-horizontal"> {% csrf_token %} <h1 class="form-signin-heading text-center">请注册</h1> <div class="form-group"> <label for="id_user_name" class="col-md-3 control-label">用户名:</label> <div class="col-md-9"> <input type="text" class="form-control" id="id_user_name" required name="username" autofocus> </div> </div> <div class="form-group"> <label for="id_passwd" class="col-md-3 control-label">密码:</label> <div class="col-md-9"> <input type="password" class="form-control" required name="passwd" id="id_passwd"> </div> </div> <div class="form-group"> <label for="id_repasswd" class="col-md-3 control-label">重复密码:</label> <div class="col-md-9"> <input type="password" class="form-control" required name="repasswd" id="id_repasswd"> </div> </div> <div class="form-group"> <label for="id_email" class="col-md-3 control-label">电话号码:</label> <div class="col-md-9"> <input type="text" class="form-control" required name="phone" id="id_phone"> </div> </div> <div class="form-group"> <div class="col-md-4 col-md-offset-4"> <button class="btn btn btn-primary btn-block" type="submit" id="id_submit">注册</button> </div> </div> </form> </div> </div> </div> {% endblock %}查看
{% extends "base.html" %} {% load staticfiles %} {% block title %}查看{% endblock %} {% block content %} <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="col-md-2"> <div class="list-group"> <a href="/viewroom/" class="list-group-item" id="id_typ_all">全部会议室</a> {% for acad in acad_list %} <!--循环学院列表--> <a href="/viewroom?acad={{ acad }}" class="list-group-item" id="id_typ_{{ acad }}">{{ acad }} </a> {% endfor %} </div> <script type="text/javascript"> var act_typ = document.getElementById("id_typ_{{acad_list}}"); var new_class = act_typ.getAttribute("class") + " active" act_typ.setAttribute("class",new_class); </script> </div> <div class="col-md-9 col-md-offset-1"> <div class="col-md-4 col-md-offset-8"> <form role="form" method="post" name="search_form"> {% csrf_token %} <input type="search" class="form-control" name="number" placeholder="Enter keywords to search" id="id_search_input" onkeyup="whenkeyup()" autofocus="True"> </form> </div> <script type="text/javascript"> function whenkeyup () { var oldvalue = document.getElementById('id_search_input').value setTimeout(function(){ var newvalue = document.getElementById('id_search_input').value if (oldvalue == newvalue) { document.search_form.submit(); }; },1500); } </script> <table class="table table-hover"> <thead> <tr> <th>会议室号</th> <th>会议室名</th> <th>大小</th> <th>详情</th> </tr> </thead> <tbody> {% for room in room_list %} <tr> <td>{{ room.num }}</td> <td>{{ room.name }}</td> <td>{{ room.size }}</td> <td><a href="/detail/?id={{room.id}}">查看</a></td> </tr> {% endfor %} </tbody> </table> <nav> <ul class="pager"> {% if room_list.has_previous %} <li class="previous"><a href="?typ={{room_acad}}&page={{ room_list.previous_page_number }}">上一页</a></li> {% else %} <li class="previous disabled"><a href="#">上一页</a></li> {% endif %} 第 {{ room_list.number }} / {{ room_list.paginator.num_pages }}页 {% if room_list.has_next %} <li class="next"><a href="?acad={{room_acad}}&page={{ room_list.next_page_number }}">下一页</a></li> {% else %} <li class="next disabled"><a href="#">下一页</a></li> {% endif %} </ul> </nav> </div> </div> </div> </div> {% endblock %}
详情,这个页面做的有点简单了:
{% extends "base.html" %} {% load staticfiles %} {% block title %}查看会议室{% endblock %} {% block content %} <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="col-md-5"> {% if img_list %} <div id="carousel-generic" class="carousel slide" data-ride="carousel"> <ol class="carousel-indicators"> {% for item in img_list %} <li data-target="#carousel-generic" data-slide-to="{{forloop.counter0}}" {% if forloop.first %}class="active"{% endif %}></li> {% endfor %} </ol> <div class="carousel-inner" role="listbox"> {% for img in img_list %} <div {% if forloop.first %}class="item active"{%else%}class="item"{% endif %}> <img src="/static/{{img.img}}"> </div> {% endfor %} </div> <a class="left carousel-control" href="#carousel-generic" role="button" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left"></span> </a> <a class="right carousel-control" href="#carousel-generic" role="button" data-slide="next"> <span class="glyphicon glyphicon-chevron-right"></span> </a> </div> {% else %} <p class="text-center">暂无图片</p> {% endif %} </div> <div class="col-md-6 col-md-offset-1"> <h2 class="text-center">{{room.name}}会议室</h2> <br> <h3>会议室名 :{{room.name}}</h3> <h3>会议室大小:可容纳{{room.size}}人</h3> <h3>可预约时间:{{ro.time}}</h3> {% if or_sta == "yes" %} <h3><a href="/order/">预约</a></h3> {% elif or_sta == "no" %} <h3>已被预约</h3> {% endif %} </div> </div> </div> </div> {% endblock %}
查看预定:
{% extends "base.html" %} {% load staticfiles %} {% block title %}查看{% endblock %} {% block content %} <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="col-md-9 col-md-offset-1"> {% if us_sta == "no" %} <table class="table table-hover"> <thead> <tr> <th>用户名</th> <th>会议室代号</th> <th>会议室名称</th> <th>会议室时间</th> <th>会议室大小</th> <th>用户电话</th> <!--<th>预约时间</th>--> <th>备注</th> </tr> </thead> <tbody> {% for order in myorder %} <tr> <td> {{ order.user }} </td> <td> {{ order.num }} </td> <td> {{ order.name }} </td> <td> {{ order.time }} </td> <td> {{ order.size }} </td> <td> {{ order.phone }} </td> <!--<td> {{ order.ntime }} </td>--> <td><a href="/cancel/?id={{order.id}}">取消定单</a></td> </tr> {% endfor %} </tbody> </table> {% else %} <h2>你还没有预约,请先预约!</h2> {% endif %} </div> </div> </div> </div> {% endblock %}最后一个:
{% extends "base.html" %} {% load staticfiles %} {% block title %}会议室预约{% endblock %} {% block content %} <div class="container"> <div class="row"> <div class="col-md-8 col-md-offset-2 well"> <h2> 恭喜你预约成功!</h2> </div> </div> </div> {% endblock %}
前端页面就这么多,有些地方直接是拷别人的,改了一下。
还有后台管理,在djapp下建立一个admin.py,这样就可以直接从后台对数据库进行管理了,比较方便。
from django.contrib import admin from djapp.models import * admin.site.register(MyUser) admin.site.register(ConfeRoom) admin.site.register(Order) admin.site.register(Detail)
花了一个月时间,从一开始的什么都不会,查资料看文档,遇到问题就百度谷歌,到现在了解了一个网站的运作过程,确实学到了不少东西。谢谢django小组,谢谢Python,谢谢开源。