04.数据显示
//注册admin用户
python3 manage.py createsuperuser
//admin.py
//注册模型进admin后台,登录admin,刷新查看新增用户
from userapp.models import User
admin.site.register(User)
//用户显示属性
//models.py User Class 内声明方法
def __str__(self):
return self.nick
//读取数据库显示
//views.py
from userapp.models import User
def hello_db(request):
peiqi = User.objects.all()[0]
return HttpResponse("你好呀,%s"%(peiqi.nick))
//urls.py
from userapp import views
urlpatterns = [
path('admin/', admin.site.urls),
path('hello/', views.hello),
path('hello2/',views.hello_db)
]