我有数据库中的城市列表,并希望在 Web 控制器中显示它们的特定数据。在这里,附上我使用的屏幕截图和代码。
Controllerrs.py 文件
from odoo import http
class CurrentWeather(http.Controller):
@http.route('/current_weather/', auth='public', website='True')
def index(self, **kw):
location = http.request.env['weather_location.weather_location']
return http.request.render('current_weather.index', {
'locations': location.search([])
})
@http.route('/current_weather/condition', auth='public', website='True')
def index_current_condition(self, **kw):
weather_condition = http.request.env['current_weather.current_weather']
return http.request.render('current_weather.index_condition', {
'weather_conditions': weather_condition.search([])
})
模板.xml 文件
<template id="index">
<t t-call="website.layout">
<t t-set="title">Locations</t>
<div class="oe_structure">
<div class="container">
<t t-foreach="locations" t-as="location">
<p>
<a t-attf-href="/current_weather/condition">
<center><t t-esc="location.name"/></center>
</a>
</p>
</t>
</div>
</div>
</t>
</template>