Step 1 创建超级用户
python manage.py createsuperuser
在终端输入
Step 2 输入用户名和密码
Step 3在网站上输入
127.0.0.1:8000/admin
Step 4创建群组和用户
让创建的组和用户可以访问网站
def index(request):
groupnames=list(request.user.groups.values('name'))
is_admins = 0
for each_groupname in groupnames:
if each_groupname['name']=='admins';
is_admins=1
if is_admins:
allRows=MyData.objects.all()
text1=[]
text2=[]
for eachRow in allRows:
text1.append(eachRow.text1)
text2.append(eachRow.text2)
return render(request,'index.html', {"text1": text1,"text2": text2})
else:
return redirect('/admin')