Python 无法在django模板中呈现选项类型
视图.pyPython 无法在django模板中呈现选项类型,python,django,django-templates,Python,Django,Django Templates,视图.py from .models import posts, TYPES //posts is a model def TypePostListView(request, type): posts = post.objects.filter(type=type).order_by('-date_posted') context = { 'posts': posts, 'p_types':TYPES } return rend
from .models import posts, TYPES //posts is a model
def TypePostListView(request, type):
posts = post.objects.filter(type=type).order_by('-date_posted')
context = {
'posts': posts,
'p_types':TYPES
}
return render(request, 'blog/home.html', context)
TYPES = (
('Food', 'Food'),
('Fashion', 'Fashion'),
('Fitness', 'Fitness'),
('Finance', 'Finance'),
('Travel ', 'Travel '),
('Music', 'Music'),
('Lifestyle', 'Lifestyle'),
('Music', 'Music'),
('Sports', 'Sports'),
('Political', 'Political'),
('Gaming', 'Gaming'),
)
型号.py
from .models import posts, TYPES //posts is a model
def TypePostListView(request, type):
posts = post.objects.filter(type=type).order_by('-date_posted')
context = {
'posts': posts,
'p_types':TYPES
}
return render(request, 'blog/home.html', context)
TYPES = (
('Food', 'Food'),
('Fashion', 'Fashion'),
('Fitness', 'Fitness'),
('Finance', 'Finance'),
('Travel ', 'Travel '),
('Music', 'Music'),
('Lifestyle', 'Lifestyle'),
('Music', 'Music'),
('Sports', 'Sports'),
('Political', 'Political'),
('Gaming', 'Gaming'),
)
home.html
<div class="type-selection">
<a href="{% url 'blog-home' %}">all</a>
{% for t in p_types %}
<a href="{% url 'type-posts' 't.0' %}">{{t.0}}</a>
{%endfor%}
</div>
{p_类型%中的t的百分比}
{%endfor%}
我无法在Django模板上呈现任何文本。我正在尝试打印模板上所有类型的帖子。也许这个问题可以帮助您: