博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
pyjamas build AJAX apps in Python (like Google did for Java)
阅读量:5719 次
发布时间:2019-06-18

本文共 2910 字,大约阅读时间需要 9 分钟。

pyjamas
build
AJAX apps in Python (like Google did for Java)

Getting Started with
pyjamas

Programming with pyjamas needs a little bit of rethinking about

the way that you do Web application development. Primarily,
you need to forget virtually everything you've ever learned and
come to expect Web development to be. The reason for this is
very simple: Pyjamas is pure javascript. Although written
in python, not javascript, it is essential to bear in mind
that virtually 100% of your web application will be javascript -
not HTML. The programming style you may be accustomed to for
HTML programming involves placing as much HTML into one page
as you can stand, and making the minimum number of exceptions
and allowances for dynamic content that you can manage, without
making the HTML page "too complicated" to be readable.

Pyjamas makes it possible for you to break pages down into concepts.

classes. widgets. maybe some CSS styling is added, almost as an
afterthought, on top of the "real" functionality. In other words, Pyjamas
is actually more like Desktop application development than it is
Web development.

With that in mind, the best possible starting point has to be the

, most of which were ported from
Google Web Toolkit. They will make it really clear just how "not"
Web that pyjamas - and incidentally GWT - really are.

Examples

The simplest example is of course the traditional

or, in this case, Hello AJAX. If you've downloaded pyjamas, you
will be able to browse, with your browser, to the examples directory
and see this in action for yourself. Type
"file://home/yourusername/pyjamas/examples" into your URL bar - or
wherever you have unpacked pyjamas to and continue to browse to
the helloworld output directory.

Once you have played with the example, online, try it on your local

machine. Remember to run the "build.sh" script (if you have linux
or MacOS, or execute python.exe ../../build/build.py Hello.py if
you have windows). Then, take a look at the source code
that generated it, which is shown here:

from pyjamas import Windowfrom pyjamas.ui import RootPanel, Buttondef greet(sender):    Window.alert("Hello, AJAX!")b = Button("Click me", greet)RootPanel().add(b)

The most important thing to note is that everything gets added to

RootPanel. RootPanel() gives you access to the Browser's
DOM model (starting of course at body). To illustrate,
try adding this, and see what happens:

RootPanel().add(HTML("Hello World"))

You should get nothing - and if you look in your Javascript

console for an error message, you should find an error indicating
that "HTML" does not exist. This is correct - because you needed to
add this to the top of the module, along with the other imports:

from pyjamas.ui import HTML

Now if you re-run build.sh, you should see both a button and next

to it the words "Hello World". Congratulations, you've just
successfully developed your first pyjamas application.

转载地址:http://dyhgt.baihongyu.com/

你可能感兴趣的文章
CCNA实验之:网络地址转换(NAT)实验
查看>>
SeeSite在win7下不能装载提示md:117的解决方法
查看>>
【转】Python 可视化神器-Plotly Express
查看>>
计算机网络原理笔记-停止等待协议
查看>>
topcoder srm 662 div1
查看>>
Java基础之静态变量
查看>>
更换好的yum源
查看>>
NET牛人应该知道些什么?
查看>>
[Asp.Net web api]基于自定义Filter的安全认证
查看>>
洛谷P3763 [TJOI2017]DNA(后缀自动机)
查看>>
确定当前记录和下一条记录之间相差的天数
查看>>
NYOJ32:组合数(DFS入门)
查看>>
使用Callable和Future接口创建线程
查看>>
BZOJ 2568 比特集合
查看>>
sql语句返回主键SCOPE_IDENTITY()
查看>>
MongoDB培训
查看>>
机器学习开源项目精选TOP30
查看>>
python基础===对字符串进行左右中对齐
查看>>
一起谈.NET技术,ASP.NET缓存全解析6:数据库缓存依赖
查看>>
ABAP程序互调用:SUBMIT、CALL TRANSACTION、LEAVE TO TRANSACTION
查看>>