Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
4724 มุมมอง

I am creating a web controller in Odoo and I want to check if the user has permission to perform an action, if it doesn't I would like to raise a 403 exception. So, how can I raise a 403 exception inside Odoo web controller? I also want to know how to raise a 404 exception as well. How can I do it?


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

To raise forbidden and not found error,You can refer the given code below:
from werkzeug.exceptions import Forbidden, NotFound

@route(['/route'], type='http',
           auth='user',
           website=True)def function(self):
     if not request.env.user.has_group( 'module_name.group_id'):         

​return Forbidden()     

     else:         

         return NotFound()

Hope it helps

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello Ernesto Ruiz,


In Odoo web controllers, you can raise a 403 Forbidden error and a 404 Not Found error using the HTTP controller. 

Please check Code in Comment. 

Hope it will be helpful to you.

Thanks & Regards,
Email:   odoo@aktivsoftware.com  

Skype: kalpeshmaheshwari

อวตาร
ละทิ้ง

EX :-
You just need to use the Odoo standard template which is <template id="page_404" name="Page Not Found">, and you can return this template in your controller (i.e., return request.render('website.page_404')) based on your user permissions.

คำตอบที่ดีที่สุด

Check this link with an answer for you

https://stackoverflow.com/a/76824681/4451876

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Data from website with controller แก้ไขแล้ว
2
ก.ค. 24
4075
0
ก.ย. 21
1859
1
มี.ค. 15
4660
1
ต.ค. 23
2668
3
พ.ย. 21
2551