在Djang中显示应用程序到网站主页的单个记录

2024-09-29 17:14:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从应用程序在网站主页上显示记录。在管理界面记录得到显示,但在网站主页上它不工作。你知道吗

场地结构

Site structure
website
--MyWebsite
----templates
--alert
----templates

警报代码/视图.py你知道吗

def weather_single(request):
    weatheronly=Weatherreport.objects.last()
    return render(request, '../MyWebsite/templates/sidebar_left.html', {'weatheronly':weatheronly})

MyWebsite/templates/sidebar上的代码_左.html你知道吗

{% for wresult in weatheronly %}
{{ wresult.temp }}
{{ wresult.forecast }}
{% endfor %}

url模式代码 urlpatterns=[网址('',views.weather\单,name='weather\u single'),]





Currently not getting any error message and no results at all.

Tags: 代码应用程序界面网站requesthtml记录主页
1条回答
网友
1楼 · 发布于 2024-09-29 17:14:49

你的考试有结果吗

weatheronly=Weatherreport.objects.last()

解决这个问题的最好方法是假设你的假设是不正确的,并检查原始数据中是否有任何数据。你知道吗

相关问题 更多 >

    热门问题