模版中的变量由context中的值来替换,如果在多个页面模版中含有相同的变量,比如:每个页面都需要{{user}},笨办法就是在每个页面的请求视图中都把user放到context中. from django.temlate import loader,Context t = loader.get_template('xx.html') c = Context({'user':'zhangsan'}) return HttpResponse(t.render(c)) #httprespon…
定义用户model时可以给用户分配权限: class Meta: permissions = ( ("can_mark", "Can mark"), ) views里的判断: if request.user.has_perm('accounts.can_mark'): 或者在模板里 {% if perms.accounts %} <p>You have permission to do something in the poll…
1. 自定义Admin from django.contrib import admin from xx import models # 自定义操作 class CustomerAdmin(admin.ModelAdmin): # 继承 admin.ModelAdmin list_display = ["name","contact_type","contact","source","consult_content&…