-
Notifications
You must be signed in to change notification settings - Fork 3
/
README
91 lines (61 loc) · 3.39 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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