Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法在django模板中呈现选项类型_Python_Django_Django Templates - Fatal编程技术网

Python 无法在django模板中呈现选项类型

Python 无法在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

视图.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'),    
)
型号.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模板上呈现任何文本。我正在尝试打印模板上所有类型的帖子。

也许这个问题可以帮助您: