Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.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 名称错误:全局名称';装载机&x27;没有定义_Python_Django - Fatal编程技术网

Python 名称错误:全局名称';装载机&x27;没有定义

Python 名称错误:全局名称';装载机&x27;没有定义,python,django,Python,Django,我想从django中的模型中获取数据。我有一个代码,但有一个名称错误。 views.py def新闻(请求): 模板:- {%if warnings%} {%for warning in warnings%} {{warning}} {%endfor%} {%endif%} {%if news_list%} {%for news in news_list%} {{news.headline}}

我想从django中的模型中获取数据。我有一个代码,但有一个名称错误。 views.py def新闻(请求):

模板:-

{%if warnings%}
 {%for warning in warnings%}
   {{warning}}
        {%endfor%}
    {%endif%}
    {%if news_list%}
        {%for news in news_list%}
            {{news.headline}}
            {{news.date}}
            {{news.content}}
            <a href="{{news.author.website}}">{{news.author.author}}</a>
        {%endfor%}
    {%endif%}
{%if警告%}
{%用于警告中的警告%}
{{警告}
{%endfor%}
{%endif%}
{%if新闻\列表%}
{新闻列表%中的新闻为%}
{{news.headline}
{{news.date}
{{news.content}
{%endfor%}
{%endif%}
请帮助我解决此问题。

使用此代码

    template = get_template("news.html") 
分期付款

    template = loader.get_template("news.html")

您的问题将得到解决。因为您已经启用了函数get\u template,所以需要使用loader。get\u template

您从
loader
导入了
get\u template
。这是基本的Python,所以我建议您在使用Django之前多读一点纯Python。您现在的行为非常糟糕。得到问题的答案后,您可以编辑标题以询问另一个不同的问题。如果这还不够糟糕,那么第二个问题的原因与第一个问题完全相同。我已回滚编辑并将投票关闭。或添加导入加载程序:
来自django.template导入加载程序
    template = loader.get_template("news.html")