1
我想从django中的模型中获取数据。我有一个代码,但有一个名称错误。 views.py 高清消息(请求):名称错误:未定义全局名称'loader'
from django import template
from django.template.loader import get_template
template_source_loaders = None
template = loader.get_template("news.html")
warning_list = []
news_list = []
blog_query = blogs.object.all()
for news_entry in blog_query:
news_list.append(news_entry)
#except Exception, e:
warning_list.append(e.message)
context = Context({
'news_list':news_list,
'warnings' :warning_list,
})
return HttpResponse(template.render(context))
模板: -
{%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%}
请帮我解决这个问题。
你进口'get_template ''来自'loader'。这是基本的Python,所以我建议你在使用Django之前再阅读一下纯Python。 – Blender
你现在表现得非常糟糕。回答你的问题后,你可以编辑标题以提出另一个不同的问题。如果这还不够糟糕,第二个问题的原因与第一个问题完全相同。我已经回滚了编辑并将投票结束。 –