Skip to Content
Menu
This question has been flagged
2 Replies
3656 Views
# # -*- coding: utf-8 -*-
from odoo import http
from odoo.http import request

class Request(http.Controller):

@http.route('/', auth='public' , type="http", website=True)
def request(self, **kw):
users = request.env["users.library"].sudo().search([])
return http.request.render('library.get_values', {
"users":users
         # here i get all records
})

@http.route('/set', auth='public', type="http", website=True)
def create(self, **post):
request.env["users.library"].sudo().create(post)
return http.request.render('library.thank', {})
        # here i cant create new record why?

------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>

<odoo>
<data>
<template id="get_values" name="create">
<t t-call="website.layout">
<div class="oe_structure">
<div class="container" style='padding:30px'>
<from role="form" action="/set" method="post">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
<div>
<label for="name">Name</label>
<input type="text" id="user_name" name="user_name" t-att-value="user_name"/>
</div>
<div>
<button type="submit">submit</button>
</div>
</from>
<t t-foreach="users" t-as="o">
<t t-esc="o.user_name"/>
<br/>
</t>
</div>
</div>
</t>
</template>
<template id="thank" name="thank">
<t t-call="website.layout">
<div class="oe_structure">
<div class="container" style='padding:30px'>
hello
</div>
</div>
</t>
</template>
</data>
</odoo>
Avatar
Discard
Author Best Answer

i follow your tutoria and when i click button submit there is no record data create in model

Avatar
Discard