文章目录
1. 展示影⽚信息
- 1. 展示影⽚信息
- 2. 实现步骤
- 3.创建视图
- 4.创建模板
- 5.配置URLconf
- 6.启动服务器
- 7.测试
- 创建视图
- 创建模板
- 配置
URLconf
# film/views.py
from django.shortcuts import render
from film.models import FilmInfo
# Create your views here.
def filmList(request):
"""
浏览器显示所有影⽚信息
:param request:
:return:
"""
# 查询filminfo表中所有数据
films = FilmInfo.objects.all()
# 构造数据
data = {'filmlist':films}
# 传递数据给模板
return render(request,'film/index.html',data)
# /templates/film/index.html
Title
{% for film in filmlist %}
{{ film.fname }}
{% endfor %}
# film/urls.py
from django.urls import re_path,path
from film import views
urlpatterns = [
re_path('^show/$',views.show),
re_path('^filmlist/$',views.filmList),
]
$ python manage.py runserver
浏览器输入:
http://127.0.0.1:8000/filmlist/