(ten) Odoo controller operation

Source: Internet
Author: User

* A simple controller
Class MyModule (HTTP. Controller)
@http. Route (' mymodule/mymodule/', auth= ' public ')
def index (self)
Return "Hello, World"
#return Http.request.render ("Mymodule.index", {' Fruits ': [' apple ', ' banana ', ' pear ']})
Using templates

The corresponding template file
<openerp>
<data>
<template id= "Index" >
<title>mymodule</title>
<t t-foreach= "fruits" t-as= "fruit" >
<p><t t-esc= "Fruit" ></p>
</t>
</template>
</data>
</openerp>

* Routing
Openerp.http.route (Route=none, **kw)
See http://werkzeug.pocoo.org/docs/0.11/routing/

* Request
Class Openerp.http.WebRequest (HttpRequest)
Encapsulated properties
Httprequest:werkzeug.wrappers.Request the original Request
Params: Parameters of the Map
ENV: Current Environment
Context: Contexts
Session: Sessions
CR: Database Manipulation handle
Debug: Whether the current debug mode
DB: The currently connected database

Class Openerp.http.HttpRequest (*args)
Make_response (data, Headers=none, Cookies=none)
Not_found (Description=none) 404 page Response
Render (template, Qcontext=none, Lazy=true, **kw) with stencil rendering

Class Openerp.http.JsonRequest (*args)
Return JSON

* Response
Class Openerp.http.Response (*args, **kw)
*args for
Template (basestring)--The specified name
Qcontext (Dict)--the context of the rendering
UID (int)--the user ID rendered to the template

Available methods
Render () renders the specified template
Flatten () forced rendering, no template used


* Controller
Class Openerp.http.Controller

Class Mycontroller (Openerp.http.Controller):
@route ('/some_url ', auth= ' public ')
def handler (self):
return Stuff ()

Covered:
Class Extension (Mycontroller):
@route ()
def handler (self):
Do_before ()
Return super (Extension, self). Handler ()

(ten) Odoo controller operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.