SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
1.
Rails vs Web2Py
From ”Ruby On Rails” to ”Web to Python”
http://jon.is.emotionull.com
2.
Controllers
class MyTestController < ApplicationController
def index
render_text “Hello World”
end
end
def index():
return "Hello World"
3.
Params
class MyTestController < ApplicationController
def index
render_text “Hello ”+params[:who]
end
end
def index():
return "Hello %s" % request.vars.who
def index():
return "Hello %s" % request.args[0]
4.
Dispatching
http://hostname/MyTest/index
class MyTestController < ApplicationController
def index
render_text “Hello World”
end
end
http://hostname/myapp/mycontroller/index calls
def index():
return "Hello %s" % request.vars.who
5.
Routing
routes.rb
routes.py (reversed routing, with or without
regex, IP filtering)
6.
Views
<table>
<% @recipes.each do |recipe| %>
<tr>
<td><%= recipe.name %></td>
</tr>
<% end %>
</table>
<table>
{{for recipe in recipes:}}>
<tr>
<td>{{=recipe.name}}</td>
</tr>
{{pass}}
</table>
7.
Passing vars in views
class MyTestController < ApplicationController
def index
@message=“Hello World”
end
end
def index():
return dict(message=”Hello World”)
8.
Layouts
<title>Layout Example</title>
<body>
<%= yield %>
</body>
</html>
<title>Layout Example</title>
<body>
{{include}}
</body>
</html>
and in view:
{{extend ‘layout.html’}}
body