Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Writing data to model from POST request

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
requestpostCSRF
2 Réponses
20150 Vues
Avatar
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
Avatar
Ignorer
Avatar
pam
Auteur Meilleure réponse

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
Avatar
Ignorer
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.

Avatar
Raaj Mishra
Meilleure réponse

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
Avatar
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
[9.0] HTTP POST request, how to solve this error ? Résolu
request http post 9.0
Avatar
2
avr. 16
5313
information request
request
Avatar
Avatar
1
juin 24
2299
Get POST parameters from an incoming request to a controller Résolu
parameters request controllers post odooV13
Avatar
Avatar
1
sept. 22
17480
Exception: Object Unbound in request Résolu
request
Avatar
Avatar
9
nov. 16
15501
Sending post request
request odoo
Avatar
Avatar
1
août 25
1340
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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