3

I wrote this inside my module controller

from odoo import http
from odoo.http import request
class Mylib(http.Controller):

    @http.route('/mylib/project', auth='public',method=['POST'], csrf=False)
    def fun_post(self):
              vals = {'name': 'The secret', 'author': 'shakesphere', 'year': 1661, 
             'book_copy': 12}

              return request.env['books.model'].create(vals)

after running this there is no record added, that may be the problem with the URL. I don't know how to put this route...I checked via postman then I got this error,

" The requested URL was not found on the server.  If you entered the 
 URL manually please check your spelling and try again"
Kenly
  • 24,317
  • 7
  • 44
  • 60

3 Answers3

1

I had the same error when using POSTMAN. I saw this answer Odoo: URL not found if not auth and then added

--db-filter=[YOUR DB]

in the odoo-bin execution command. don't add in odoo.conf

Kenly
  • 24,317
  • 7
  • 44
  • 60
teguhteja
  • 33
  • 7
0

Hope the indentation of your function is correct and is defined inside the class Mylib.

If you are calling this URL from an external source or without logging into the system you have to mention the DB details if you have multiple DBS.

Kenly
  • 24,317
  • 7
  • 44
  • 60
Prasoon
  • 48
  • 9
0

Try with the following code: I added type='json' in the argument and return a string instead of books.model recordset.

@http.route('/mylib/project', type='json', auth='public', method=['POST'], csrf=False)
def fun_post(self):
    vals = {'name': 'The secret', 'author': 'shakesphere', 'year': 1661,
            'book_copy': 12}
    request.env['books.model'].create(vals)
    return "OK"

If still not working, add dbfilter=YOUR-DB-NAME in the .conf file or if you run the server from the command line then add -d YOUR-DB-NAME

Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58