怎麼在本身的項目里加入 bootstrap 和 jqucry ?html
下載下來再拷貝到項目裏(jqucry1.0支持IE 8,9的)前端
前端展現用戶列表:django
自定義分頁(模塊化)bootstrap
把分頁寫成模塊,之後用到分頁的時候能夠調用:session
一、在Django中先生成一個app00,註冊,配置url&viewsapp
from django.conf.urls import url from django.contrib import admin from app00 import views urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^user_list/',views.user_list), ]
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'app00', ]
from django.db import models class UserProfile(models.Model): user = models.OneToOneField(User) #alex name = models.CharField(max_length=64) school = models.ForeignKey('School')
二、分頁代碼ide
from django.shortcuts import render,redirect import models from django.core.paginator import Paginator,EmptyPage,PageNotAnInteger from crm import forms from permissions import check_permission # Create your views here. def dashboard(request): return render(request,'crm/dashboard.html') @check_permission def customers(request): customer_list = models.Customer.objects.all() paginator = Paginator(customer_list,3) page = request.GET.get('page') try: customer_objs = paginator.page(page) except PageNotAnInteger: customer_objs = paginator.page(1) except EmptyPage: customer_objs = paginator.page(paginator.num_pages) return render(request,'crm/customers.html',{'customer_list':customer_objs}) @check_permission def customer_detail(request,customer_id): customer_obj = models.Customer.objects.get(id=customer_id) if request.method == "POST":#後臺判斷POST form = forms.CustomerModelForm(request.POST,instance=customer_obj) #print(request.POST) if form.is_valid():#修改以前先做驗證 form.save() print( 'url:',request.path)#獲取url base_url = "/".join(request.path.split("/")[:-2]) print( 'url:',base_url) return redirect(base_url) #else: else: form = forms.CustomerModelForm(instance=customer_obj) return render(request,'crm/customer_detail.html',{'customer_form':form})
{% extends 'base.html' %} {% load custom_tags %} {% block page-header %} 客戶信息列表 {% endblock %} {% block page-content %} <table class="table table-hover"> <thead> <tr> <th>ID</th> <th>QQ</th> <th>姓名</th> <th>渠道</th> <th>諮詢課程</th> <th>課程類型</th> <th>客戶備註</th> <th>狀態</th> <th>課程顧問</th> <th>日期</th> </tr> </thead> <tbody> {% for customer in customer_list %} <tr> <td><a href="{% url 'customer_detail' customer.id %}">{{ customer.id }}</a></td> <td>{{ customer.qq}}</td> <td>{{ customer.name}}</td> <td>{{ customer.source}}</td> <td>{{ customer.course}}</td> <td>{{ customer.get_course_type_display}}</td> <td>{{ customer.consult_memo|truncatechars:50}}</td> <td class="{{ customer.status }}">{{ customer.status|alex_upper }}</td> <td>{{ customer.consultant}}</td> <td>{{ customer.date}}</td> </tr> {% endfor %} </tbody> </table> <div class="pagination"> <nav> <ul class="pagination"> {% if customer_list.has_previous %} <li class=""> <a href="?page={{ customer_list.previous_page_number }}" aria-label="Previous"> <span aria-hidden="true">«</span> </a> </li> {% endif %} {% for page_num in customer_list.paginator.page_range %} {% guess_page customer_list.number page_num %} {% endfor %} {% if customer_list.has_next %} <li class=""><a href="?page={{ customer_list.next_page_number }}" aria-label="Next"><span aria-hidden="true">»</span></a></li> {% endif %} </ul> </nav> </div> {% endblock %}
def customers(request): customer_list = models.Customer.objects.all() paginator = Paginator(customer_list,3) page = request.GET.get('page') try: customer_objs = paginator.page(page) except PageNotAnInteger: customer_objs = paginator.page(1) except EmptyPage: customer_objs = paginator.page(paginator.num_pages) return render(request,'crm/customers.html',{'customer_list':customer_objs})
分頁代碼模塊化
<div class="pagination"> <nav> <ul class="pagination"> {% if customer_list.has_previous %} <li class=""> <a href="?page={{ customer_list.previous_page_number }}" aria-label="Previous"> <span aria-hidden="true">«</span> </a> </li> {% endif %} {% for page_num in customer_list.paginator.page_range %} {% guess_page customer_list.number page_num %} {% endfor %} {% if customer_list.has_next %} <li class=""><a href="?page={{ customer_list.next_page_number }}" aria-label="Next"><span aria-hidden="true">»</span></a></li> {% endif %} </ul> </nav> </div>
from django import template from django.utils.html import format_html register = template.Library() @register.filter def alex_upper(val): print("--val from template:",val ) return val.upper() @register.simple_tag def guess_page(current_page,loop_num): offset = abs(current_page - loop_num) if offset <3: if current_page == loop_num: page_ele = '''<li class="active"><a href="?page=%s">%s</a></li>''' %(loop_num,loop_num) else: page_ele = '''<li class=""><a href="?page=%s">%s</a></li>''' %(loop_num,loop_num) return format_html(page_ele) else: return ''
通用權限系統的設計思路:oop
加權限是由於但願不一樣的角色有不一樣的權限,不一樣的角色作的事情是不同的。url