Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
12712 Lượt xem
class ProjectExtension(http.Controller):
    @http.route('/project_extension/project_extension/', auth='public', website=True)    def index(self, **kw):
        Projects = http.request.env['project.project']        return http.request.render('project_extension.index', {            'projects': Projects.search([])        })
@http.route('/project_extension/a/', auth='public', website=True)def task(self, project):
    return http.request.render('project.project', {        "project" : project    })


 Hello

I'm trying to display some information on the website for a client.

I have a module, project_extension, which expend the Project module.

The first part of my code display a liste of project and the second part should display the tasks linked to this project, but at list I would like juse to have a page. Because actually I juste have a

404: Page not found!

error when clinking on a link.

I build the link like this :

<t t-foreach="projects" t-as="project">
    <p><a t-attf-href="/project_extension/{{ slug(project) }}">                               
        <t t-esc="project.name"/></a>                              
    </p>                       
</t>

I hope someone can help me.

I tried to follow the Building a website tutorial (and my little module is working, I can display a teacher and click on it to display his biography)


Thx for your help


Célia

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

You should give the read access to the public for your model using csv file.

access_your_model,access_your_model,model_your_model,,1,0,0,0

You can print model objects without using python code.  Like

<t t-foreach="request.env['your.model'].search([])" t-as="obj">
    <t t-esc="obj.name"/>
</t>


Ảnh đại diện
Huỷ bỏ

How to give read access to the public? the csv is same as mentioned above but records are not viewing

Câu trả lời hay nhất

Hello,
please write code like below in controllers.py file

@http.route('/project_extension/project_extension', auth='public', website=True)    def index(self, **kw):
        # return "Hello World"        projects = http.request.env['<YOUR_MODEL_NAME>'].search([])        return http.request.render('<YOUR_MODEL_NAME>.<TEMPLATE_NAME>', {            'projects': projects,        })


write below code in <YOUR_MODEL>/views/file_name.xml


<odoo>    <data>        <template id="index">
                <t t-set="title">Academy</t>                 <div class="oe_structure">                    <div class="container">                        <t t-foreach="project" t-as="projects">                          <p><t t-esc="project.id"/> <t t-esc="project.name"/></p>                        </t>                    </div>                </div>
        </template>     </data></odoo>


After doing this please update your module. for that you need to go >apps> search your model> click on upgrade>

Please let me know if you are still facing issue with the same.


Thanks & Regards,

Siddharth Gajjar

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

like this,

@http.route( ["/user/payment_method/<model('res.partner'):partner>"], type='http', auth="user", methods=['GET'], website=True)

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 7 17
4036
2
thg 12 21
24374
3
thg 7 21
21283
0
thg 1 21
2184
2
thg 7 20
4254