1、创建模型
BugCalendar > hunter > models.py
from django.db import models
# 白帽子的基本信息
class UserInfo(models.Model):
# 白帽子昵称
nick = models.CharField(max_length=32, blank=False, verbose_name="白帽子内容")
# 白帽子邮箱
email = models.EmailField(verbose_name="白帽子邮箱")
# 活动信息
class Activity(models.Model):
# 活动标题
title = models.CharField(max_length=64, blank=False, verbose_name='活动标题')
# 活动内容
context = models.TextField(verbose_name='活动内容')
2、激活模型
BugCalendar > settings.py
INSTALLED_APPS = [
'hunter.apps.HunterConfig',
...
]
python manage.py makemigrations
python manage.py migrate hunter 0001
3、测试数据
python manage.py shell
4、视图
BugCalendar > hunter > views.py
from . import models
def show_hunter(request):
all_hunter = models.UserInfo.objects.all()
context = {'all_hunter':all_hunter}
template_name = 'hunter/show_hunter.html'
return render(request, template_name, context)
5、模型
BugCalendar > hunter > templates > hunter > show_hunter.html
<table>
<tr>
<th>昵称</th>
<th>邮箱</th>
</tr>
<tr>
{% for hunter in all_hunter %}
<td> {{hunter.nick}} </td>
<td> {{hunter.email}} </td>
{% endfor %}
</tr>
</table>
6、路由
BugCalendar > BugCalendar > urls.py
from django.urls import path
urlpatterns = [
path('calendar/', include('hunter.urls')),
]
BugCalendar > hunter > urls.py
from django.urls import path
from . import views
urlpattern = [
path('hunter/', views.show_hunter, name='show_hunter')
]