Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2112 Lượt xem

Please could you help me resolve the problem of template not rendered for a controller - appended are the codes for the same :

from odoo import http

class Books(http.Controller):

@http.route("/library/books", auth='public')

def list(self, **kwargs):

Book = http.request.env["library.book"]

books = Book.search([])

return http.request.render(

"library.book_list_template",{'book': books}

)

<odoo>

<template id="book_list_template" name="Book List">

<div id="wrap" class="container">

<h1>Booksh1>

<t t-foreach="books" t-as="book">

<div class="row">

<span t-field="book.name" />,

<span t-field="book.date_published" />,

<span t-field="book.publisher_id" />

div>

t>

div>

template>

odoo>


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

here you are given an error because are passing 'book' and on XML side are you using for loop on books

correct this way here:

from odoo import http

class Books(http.Controller):

@http.route("/library/books", auth='public')
def list(self, **kwargs):
Book = http.request.env["library.book"]
books = Book.search([])
return http.request.render(
"library.book_list_template", {'books': books}
)

in XML side use:

t-foreach="books"t-as="book"


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 4 21
5128
1
thg 8 22
2977
0
thg 5 22
2660
1
thg 4 21
5265
0
thg 2 25
931