TAILIEUCHUNG - Web to py enterprise web framework - p 15

EXECUTION ENVIRONMENT 125 models and controllers are designed to be executed in a prepared environment that has been prepopulated with web2py global objects (request, response, session, cache and T) and helper functions. This is necessary because Python is a statically (lexically) scoped language, whereas the web2py environment is created dynamically. web2py provides the exec environment function to allow you to access models and controllers directly. exec environment creates a web2py execution environment, loads the file into it and then returns a Storage object containing the environment. The Storage object also serves as a namespacing mechanism. Any Python file designed to be executed. | EXECUTION ENVIRONMENT 125 models and controllers are designed to be executed in a prepared environment that has been prepopulated with WEB2py global objects request response session cache and T and helper functions. This is necessary because Python is a statically lexically scoped language whereas the WEB2py environment is created dynamically. WEB2py provides the exec_environment function to allow you to access models and controllers directly. exec_environment creates a WEB2py execution environment loads the file into it and then returns a Storage object containing the environment. The Storage object also serves as a namespacing mechanism. Any Python file designed to be executed in the execution environment can be loaded using exe environment. Uses for exe environment include Accessing data models from other applications. Accessing global objects from other models or controllers. Executing controller functions from other controllers. Loading site-wide helper libraries. This example reads rows from the user table in the cas application 1 from import exec_environment 2 cas exec_environment applications cas models 3 rows cas .db .select Another example suppose you have a controller that contains 1 def some_action 2 return dict remote_addr Here is how you can call this action from another controller or from the WEB2py shell 1 from import exec_environment 2 other exec_environment applications app controllers request request 3 result In line 2 request request is optional. It has the effect of passing the current request to the environment of other . Without this argument the environment would contain a new and empty apart from request object. It is also possible to pass a response and a session object to exe environment. Be careful when passing request response and session objects modification by the called action or coding dependencies in the called .

TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
41    188    5    23-12-2024
28    158    1    23-12-2024
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.