-
Notifications
You must be signed in to change notification settings - Fork 3
ojuba-org/okasha
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
okasha WSGI web fromwork =========================== this is almost do-nothing web framewrok the only needed file is okasha and the rest is a sample project for demonstration see: * http://ojuba.org/ * https://github.com/ojuba-org/okasha The Name ========== Okasha (or Okkasha with double stressed) means something that interconnected, and it also means the spider or its web. We named our project after one of the companions of prophet Muhammad (peace be upon him). His full name was Okasha ibn Muhsun عكاشة بن محصن Features ========= * WSGI-enabled ie. can be used with mod_wsgi, mod_python, fast cgi, cgi, with paste or even without even a server * light weight * can be tuned to be suitable for desktop apps or public web servers * no extra dependencies * very simple The Concept ============ subclass baseWebApp and each non-private method will serve a page with same name, methods receives Request object and the rest of Uri parts (for example if you web app is app, and if the method is view and someone visited http://localhost/app/view/book1/page2 it will receive 'book1','page2' after the request argument) you may set response code and content type using the response property of Request object you may use @expose decorator to pass the returned value to some template method, the two most common template methods are * jsonDumps which will format the returned python object as a JSON javascript string. * formatTemplate - the returned dictionary or array will be the arguments to format the template files using python str.format * percentTemplate - the returned dictionary will be the arguments to format the template files using python % operator (something like C printf) * okasha.kidTemplate - the returned dictionary will be the arguments to format the kid template files and it also allow you to serve static files directly or redirect it to where it can be server by other means using the above ways one can create very effective web applications, just serve a static main HTML page (or use templates) then do the rest with AJAX/JSON Note: formatTemplate is very useful for Html but not when it contains js function because you have to escape { } into {{ }} Note: percentTemplate is very useful when Html code contains js functions but it's annoying when you got styles with % as you have to escape it into %% Does it depends on jQuery ? ============================= no, I've used it in the sample test.py for convenience, you may use any javascript library or write your own for example you may send ajax requests as in this tutorial http://www.w3schools.com/Ajax/ajax_browsers.asp Testing ======== you can test it by using python-paste for example to test the demonstration sample just run test.py then open your browser on the reported site Apache Deploying ================= install mod_wsgi and the next line to your httpd configuration WSGIScriptAlias /myapp /path/to/myapp.wsgi where /myapp is how your application is accessed (http://localhost/myapp) and where myapp.wsgi is a python file that just defines "application" for example it could be something like this from mymodule import myWebApp application=myWebApp(args_goes_here) see test.wsgi for details Google App Engine Deploying ============================ Just use the function run_wsgi_app(application) for details visit http://code.google.com/appengine/docs/python/tools/webapp/utilmodule.html#run_wsgi_app