Python Server Pages

From Lianjapedia
Revision as of 20:40, 10 April 2019 by Barrymavin (Talk | contribs)

Jump to: navigation, search

Lianja Cloud Server has built-in support for Python Server Pages.

The Lianja Cloud Server embeds Python.

Python Server Pages provide the ability to write the client in JavaScript and the server code in Python. If you know Python and HTML these are for you. You are not required to learn any new programming language in order to build custom Web and Mobile Apps.

Python Server Pages have embedded Lianja database and OData support and they are fast as the whole engine is written in C/C++, no Java or other dependencies required.

You can write and test Python Server Pages in the Lianja App Builder and "Publish to the Cloud website" to deploy them.

Page processing directives

Page Directive Description
<%= expression %> Evaluates and outputs expression.
<% code %> Executes code.
<%@ include=cExpression %> Includes the file specified in cExpression.
<%@ codebehind=cExpression %> Executes the script file specified in cExpression.

When a Python Server Page is executed the following are available to the script (in addition to the built-in Python functions). These should be familiar to PHP Web developers as they use the same naming convention.

Global associative arrays(objects)

Array Description
_ARGS[] Contains all arguments passed to the jssp page.
_COOKIE[] Contains cookie names and values.
_FILES[] Contains information about uploaded files.
_GET[] Contains GET parameter names and values.
_POST[] Contains POST parameter names and values.
_REQUEST[] Contains all arguments passed to the pysp page.
_SERVER[] Contains server information.
_SESSION[] Contains session information.

Global objects

Lianja

Method Description
Lianja.evaluate( vfp_expression ) Evaluates vfp_expression and returns the result.
Lianja.execute( vfp_command ) Executes vfp_command.
Lianja.openDatabase( databasename ) Opens the database databasename and returns an object reference.

Database

Method Description
close() Closes the database.
openRecordSet( table_or_sqlselect ) Opens a recordset for table_or_sqlselect and returns an object reference.

Recordset

Property Type Description
bof Boolean (R) Whether record pointer is at beginning of the recordset.
eof Boolean (R) Whether record pointer is at end of the recordset.
fieldcount Numeric (R) Number of fields in the recordset.
filter Character (RW) Filter expression to restrict records.
found Boolean (R) Whether the last seek or find operation found a match.
index Character (RW) Name of the index tag.
nomatch Boolean (R) Whether the last seek or find operation did not find any matches.
recno Numeric (R) Current record number in the recordset.
reccount Numeric (R) Number of records in the recordset.


Method Description
close() Closes the recordset.
delete() Marks the current record in a table recordset for deletion.
edit() Puts the current record in edit mode prior to field value modification. Complete the modification by calling update().
field( name_or_number ) Returns an object reference to the specified field in the current record.
findFirst( condition ) Moves the record pointer to the first record to match the condition.
findLast( condition ) Moves the record pointer to the last record to match the condition.
findNext( condition ) Moves the record pointer to the next record to match the condition.
findPrevious( condition ) Moves the record pointer to the previous record to match the condition.
move( numrecords, numbookmark ) Moves the record pointer by numrecords number of records from the numbookmark position.
moveBookmark( numbookmark ) Moves bookmark to the specified record number numbookmark in the recordset.
moveFirst() Moves the record pointer to the first record in the recordset.
moveLast() Moves the record pointer to the last record in the recordset.
moveNext() Moves the record pointer to the next record in the recordset.
movePrevious() Moves the record pointer to the previous record in the recordset.
moveRelative( numrecords ) Moves the record pointer by numrecords number of records.
requery() Requeries the recordset.
update() Completes an edit() method operation.

Field

Property Type Description
decimals Numeric (R) Field decimal places.
name Character (R) Field name.
type Numeric (R) Field data type.
value Expr (RW) Field value.
width Numeric (R) Field width.

Response

Method Description
Response.addCookie(name, value) Sends specified cookie.
Response.addHeader(name, value) Sends specified response headers.
Response.appendToLog( message ) Writes message to the end of the system log.
Response.authenticate( [message] ) Causes the browser to prompt for username/password with optional message.
Response.clear() Clears the output buffer.
Response.flush() Flushes out the buffers and sends to the browser.
Response.include( filename ) Includes filename.
Response.redirect( url ) Redirects to url.
Response.write( text ) Writes text.
Response.writeFile( filename ) Writes out the contents of filename.

Built-in commands/functions

Function Description
die(message) Terminates the session and displays the HTML encoded message.
debugout(message) Writes message to the debug output file.
echo( cExpression ) Evaluates and outputs cExpression.
getParameter(param, defaultvalue) Returns a named parameter from the request.
move_uploaded_file(tofilename, fromfilename) Moves the uploaded file tofilename to the location specified in fromfilename.
odata_Create( url, jsondatastring ) Inserts a new record described by the specified OData url whose field names and values are in the specified JSON encoded string e.g. '{"name":"smith", "salary":1000}'
odata_Delete( url, jsondatastring ) Deletes the record described by the specified OData url whose field names and values are in the specified JSON encoded string e.g. '{"name":"smith"}'
odata_Read( url [, filename] ) Queries data based on the specified OData url and sends the JSON encoded data back to the browser. If "filename" is specified the JSON data is saved into the specified file.
odata_Update( url, jsondatastring ) Updates a record described by the specified OData url with field names and values as specified by the JSON encoded string e.g. '{"name":"smith", "salary":1000}'
print( cExpression ) Evaluates and outputs cExpression.
tmpnam() Returns a temporary file name.
unlink( filename ) Deletes the file filename.
All of the VFP commands and functions supported by Lianja Using:

Lianja.execute( vfp_command )
result = Lianja.evaluate( vfp_expression )

View an example Python Server Page.