Guide language:

Wrote a simple basketball information management system, to share with you, if there are deficiencies, please point out the ape friends, we refueling together!

Function:

The realization of players and other information to add, delete, change and check, as well as write front-end interface display.

Main code:

1. Perform operations on player information

def qiuyuan(request): qiuyuans = models.qiuyuan.objects.all() pn=request.GET.get('pn',1) try: pn=int(pn) except: Pn =1 # search keyword= request.get.GET ('keyword',None) if keyword is not None: qiuyuans=models.qiuyuan.objects.filter(xingming__icontains=keyword).all() else: Qiuyuans = models. Qiuyuan. Objects. All () # paging, previous and next page paginator = paginator (qiuyuans, 5) # a1: query result set a2: number each page shows a try: Qiuyuans = paginator. Page (pn) # page for a record the except (EmptyPage InvalidPage, PageNotAnInteger) as e: Pn =1 qiuyuans=paginator. Page (pn) # get total pages num_pages=qiuyuans.paginator. Num_pages # get 5 numbers, If num_pages <=2: start=1 end=6 elif pn>num_pages-2: start=num_pages-1 end=num_pages+1 else: start=pn-2 end=pn+3 else: start=1 end=num_pages+1 numbers=range(start,end) context = { 'qiuyuan': 'active', 'qiuyuans': qiuyuans, 'num_pages':num_pages, 'numbers':numbers, 'pn':pn, } return render(request,'houtai/qiuyuan.html',context) 2. Add info function {% extends 'houtai/base.html' %} {% block main %} <table class="table table-bordered" method="post"> <tr> < th > ID < / th > < th > player name < / th > < th > player nationality < / th > < th > jersey number < / th > < th > position < / th > < th > players age < / th > < th > size < / th > < th > player weight < / th > The < th > the club < / th > < th > action < / th > < / tr > {% for qy in qiuyuans %} < tr > < td > {{qy. Id}} < / td > < td > {{qy. Xingming}} < / td > < td > {{ qy.guoji }}</td> <td>{{ qy.haoma }}</td> <td>{{ qy.weizhi }}</td> <td>{{ qy.nianling }}</td> <td>{{ qy.shenggao }}</td> <td>{{ qy.tizhong }}</td> <td>{{ qy.jlb.mingcheng }}</td> <td> <a href="{% url 'houtai:qy_del' %}? Id = {{qy. Id}} "onclick =" return confirm (' are you sure you want to delete it ') "> delete < / a > < a href =" {% url 'qy_edit' %}? Id = {{qy. Id}} "> change < / a > < / td > < / tr > {% endfor %} < / table > < tr > < submit > < a href =" {% url 'qy_add' %} "> add < / a > < / submit > < / tr > <! Page template --> {% include 'houtai/qy_page.html' %} {% endblock %} 3. <form class="form-vertical" action="? Id ={{qy.id}}" method="post"> <div class="form-group col-md-6 col-md-offset-3"> <lable> <input type="text" Class ="form-control" placeholder=" name="xingming" value="{{qy.xingming}}"> </div> <div class="form-control" placeholder=" name="xingming" value="{{qy Col-md-offset -3"> <lable> </lable> <input type="text" class="form-control" placeholder=" name="guoji" Value ="{{qy.guoji}}"> </div> <div class="form-group col-md-6 col-md-offset-3"> <lable> <input type="text" Class ="form-control" placeholder=" name="haoma" value="{{qy.haoma}}"> </div> <div class="form-group col-MD-6" Col-md-offset "> <lable> <lable> <input type="text" class="form-control" placeholder=" placeholder "name="weizhi" Value ="{{qy.weizhi}}"> </div> <div class="form-group col-md-6 col-md-offset-3"> <lable> <input type="text" Class ="form-control" placeholder=" player age "name="nianling" value="{{qy.nianling}}"> </div> <div class="form-group col-MD-6" Col-md-offset "> <lable> <input type="text" class="form-control" placeholder=" shenggao" name="shenggao" Value ="{{qy.shenggao}}"> </div> <div class="form-group col-md-6 col-md-offset-3"> <lable> <input type="text" Class ="form-control" placeholder=" player weight "name="tizhong" value="{{qy.tizhong}}"> </div> <div class="form-group col-MD-6 Col-md-offset -3"> <lable> <select class="form-control" name="jlb_id"> {% for jj in jianjies %} {% if jj.id == qy.jlb_id %} <option value="{{jj.id}}" selected="selected">{{jj.mingcheng}}</option> {% else %} <option value="{{jj.id}}">{{jj.mingcheng}}</option> {% endif %} {% endfor %} </select> </div> <div class="form-group col-md-6 Col-md-offset "> < form type="submit" class="form control BTN btn-danger" value=" modify "> </div> </form>Copy the code

Effect:

1. Administrator interface

2. Foreground interface

3. Login page

Recently, many friends have sent messages to ask about learning Python. For easy communication, click on blue to join the discussion and answer resource base