[django]詳情頁列表頁
阿新 • • 發佈:2018-09-18
取數據 pro 表數據 har info gop text doc 小結
詳情頁列表頁
列表頁展示titile--這個模型的部分字段
詳情頁展示這個模型的所有字段
我想看下related_name這個從主表取子表數據
取數據--官網投票例子
https://docs.djangoproject.com/en/2.1/intro/tutorial02/
polls/models.py from django.db import models class Question(models.Model): question_text = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): question = models.ForeignKey(Question, on_delete=models.CASCADE) choice_text = models.CharField(max_length=200) votes = models.IntegerField(default=0)
polls/views.py
from django.shortcuts import get_object_or_404, render
from .models import Question
# ...
def detail(request, question_id):
question = get_object_or_404(Question, pk=question_id)
return render(request, 'polls/detail.html', {'question': question})
類別 tag 文章/出版社 作者 圖書
小結
url
列表/詳情
1.(文章)一個model情況
view
列表/詳情
1.(文章)一個model情況
問題: titile
選項: choice: get_object_or_404
2.問題選項.(主表.次表_set)
model
related_name
[django]詳情頁列表頁