Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

Writing data to model from POST request

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
requestpostCSRF
2 Răspunsuri
20171 Vizualizări
Imagine profil
pam

I'm new to Odoo and trying to understand the basics of how to save data to your model from a POST request like the following

curl -X POST --data "name=Mysterious Odoo&author_ids=Doge" http://0.0.0.0:8069/test

I couldn't find any examples online and the docs don't help me either. In Odoo Development Cookbook it says Odoo intermingles with GET and POST parameters and passes them as keyword argument to the handler. However, I can't get my code running without getting `400 Bad Request. Invalid CSRF Token`: 

@http.route('/test', type='http', auth='none', methods=['POST'])	
def test(self, **kwargs):
  record = request.env['library.book']
  record.create(kwargs)


Any pointer to solve this would be appreciated.

0
Imagine profil
Abandonează
Imagine profil
pam
Autor Cel mai bun răspuns

I can't comment since I don't have enough Karma so I have to post this way. 

Thanks Raaj, appreciate your efforts. My post request is supposed to come from a third party like an API though. I figured out by setting `csrf=False` and adding sudo like so

record = request.env['library.book'].sudo()

I get my post request inserted into my model as wanted. However, I was wondering if there is way to get rid of the sudo()?

0
Imagine profil
Abandonează
Raaj Mishra

If you are doing the operations using superuser of the system i.e, Admin then sudo() not required, but if the logged in user is not having the superuser access right,in that case we need to use sudo(), however under settings->user->select the user->Administration drop-down and there you can select settings and can configure other rights also.So in that case i hope we don't need to use sudo() for creating and storing the records.

Imagine profil
Raaj Mishra
Cel mai bun răspuns

Hi Pam, as far I can unserstand you want to store the Book name and Author id using a POST request.Please have a look at the procedure below and give a try.

Create an HTML file:

<html>

    <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">

    <script src="http://code.jquery.com/jquery-1.10.2.js"></script>

    <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

        <div id="ehtml_form">

        <form method="POST" action="http://0.0.0.0:8069/form/insert_library_book">

        <label for="book_name"><b>Book Name(*)</b></label>

        <input type="text" id="book_name" name="book_name" required/><br>

        <label for="author_name"><b>Author Name(*)</b></label>

        <input type="text" id="author_name" name="author_name" required/><br> <br>

        <input type="hidden" name="form_id" value="8"/>

        <input type="submit" value="Submit Form"/>

        </form>

        </div>

</html>

Then write a controller method like,

@http.route('/form/insert_library_book', type='http', website=True, auth="public" ,csrf=False)

def insert_library_book(self, **kwargs):

    record = request.env['library.book']

    record.create(kwargs)

0
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
[9.0] HTTP POST request, how to solve this error ? Rezolvat
request http post 9.0
Imagine profil
2
apr. 16
5337
information request
request
Imagine profil
Imagine profil
1
iun. 24
2307
Get POST parameters from an incoming request to a controller Rezolvat
parameters request controllers post odooV13
Imagine profil
Imagine profil
1
sept. 22
17503
Exception: Object Unbound in request Rezolvat
request
Imagine profil
Imagine profil
9
nov. 16
15514
Sending post request
request odoo
Imagine profil
Imagine profil
1
aug. 25
1351
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now