Flask is a very lightweight REST framework for python, here is a very basic tutorial to get started.
install Flask,
pip install flask,
then create one module to test the flask.
hello world test,
then run the web server,
now http://localhost:8000/, you will see the hellofalsk page,
test to list folders and return as Json,
here we put prefix in the url template. in the method we can assess the url passed from user side.
test to get the request information, like the user-agent. just import the global request.
Thursday, February 14, 2013
Python REST Framework FLASK
Silverlight load 98% on MAC and stuck there.
you may get some 98% loading and never ends,
basically this means the Silverlight plugin is crashed anyhow. so just remove the plugin and instll it again, to do that,
Open the Finder:
HD>LIbrary>Internet Plugins folder: move to the trash Silverlight.plugin
HD>Library>Applications Support>Microsoft: move the Silverlight folder to the trash.
Also, check in Your User Account>Library>(same end locations as above).
then restart Safari.
Testing Python for C# programmers
''' @author: Android.Y.You def main(): #format output #using type to get type information import math #comment,doc SayHello("ss") #PrimeNumbers, else with for means no match. #lambda expression #keyboard input #list list=range(1,3) #tuples, tuples are immutable #dictionary d={"one":"1","two":"2"} #write a object import pickle #file path #walk for files
#AOP, using the decroator @logaop
GetInfomrationFromDB("test") |
output
******************** |
Thursday, February 7, 2013
Test Twisted Python on windows
Twisted is one popular event-driven network engine writen in python. basically, it can create a web server as the node.js do, and also provide the similar features as socket io like the pub/sub through internet. to test it, we need install python, and load the necessary dependencies. and PIP is one tool to do the package installation for you. here are some basic steps to test twisted.
Install python 2.7, just download the installer the run it, then put the path of the installed directory to system path environment. I just installed it under c:\python27. then we can run python to launch the interactive shell.
then install the pip utility.
PIP require setuptools utility, http://pypi.python.org/pypi/setuptools
you can pickup the exe download, or just download the 64 bit setup script. then download the pip package. and extract it to a local folder.
when done, it will create some utility under the python27 scripts folder, like pip.exe. then we can add this folder the system path env as well.
Install twisted, for the twisted , it require zope.interface. now we have pip, just run pip install zope.interface to install the dependency.
Now download the twisted windows installer http://twistedmatrix.com/trac/, click and good to go.
after all done, we can open the python shell, and list the twisted package.