'   '
django-admin.py startproject mysite


/settings.py

DATABASE_ENGINE = 'mysql'
DATABASE_NAME = 'mysite_db'
DATABASE_USER = ...
rails mysite


/config/database.yml

development:
      adapter: mysql
      encoding: utf8
      database: mysite_db
    ...
mysite/
                          mysite/
    __init__.py
                              app/
    manage.py
               ...
/db/schema.rb

ActiveRecord::Schema.define(:version => 0) do
    create_table :posts do |t|
        t.string   :title
    ...
/blog/models.py


class Post(models.Model):
    title = models.CharField( max_length=120 )
    description = models.TextFi...
class AddDetailsToProducts < ActiveRecord::Migration

      def self.up
          add_column :posts, :category, :string
  ...
Class Table Inheritance


class Person(models.Model):
    name = models.CharField( max_length=120 )


class Worker( Person...
/urls.py

(r'^blog/(?P<post_id>d+)', blog.views.show_post),



/blog/views.py

def show_post(request, post_id):

    post ...
GENERIC VIEWS

/urls.py

#Url: /blog/123

(r'^blog/(?P<object_id>d+)',
    'django.views.generic.list_detail.object_detail...
/app/controllers/blog_controller.rb

# URL: /blog/post/123
def post
    @post = Post.find( params[:id] )
end

# Template: ...
/app/views/layouts/blog.html.erb

<html><body>
    <h1>
        <%= link_to „Blog‟, :controller => „blog‟ %>
    </h1>
   ...
/blog/main.html

<html>
    <head>
         <title>
             {% block title %}Blog{% endblock %}
         </title>
   ...
/blog/forms.py

Class PostForm(ModelForm):
    class Meta:
        model = Post


/blog/create.html

{% block title %}Crea...
manage.py startapp blog


INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.con...
Rails::Initializer.run do |config|
  config.gem "haml"
  config.gem "chronic", :version => '0.2.3'
  config.gem "hpricot",...
script/generate controller Blog
      exists app/controllers/
      exists app/helpers/
      create app/views/blog
   > e...
Doctests
def my_func(a_list, index):
    """
    >>> a = ['larry', 'curly', 'moe']
    >>> my_func(a, 0)
    'larry'
    >...
Guides.rubyonrails.orgWorking With Rails
• Web applications for information management
• Reusable components
• Common functionalities built-in
  - Authentication
 ...
•   Less common web applications
•   AJAX intensive
•   Dedicated hosting and support
•   Heavy testing
•   Specialized to...
Content

• http://superjared.com/entry/rails-versus-django/

• http://wiki.alcidesfonseca.com/rails-vs-django/

• http://w...
Photos

•   Title - http://www.flickr.com/photos/dunechaser/2936384537/
•   Introduction - http://www.flickr.com/photos/du...
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Django Vs Rails
Upcoming SlideShare
Loading in...5
×

Django Vs Rails

11,853

Published on

A short comparison of the Ruby on Rails and Django web frameworks.

Presented at BarCampPT 2009.9

Published in: Technology
0 Comments
13 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
11,853
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
169
Comments
0
Likes
13
Embeds 0
No embeds

No notes for slide

Django Vs Rails

  1. 1. ' '
  2. 2. django-admin.py startproject mysite /settings.py DATABASE_ENGINE = 'mysql' DATABASE_NAME = 'mysite_db' DATABASE_USER = 'sergio' DATABASE_PASSWORD = 'qwerty' DATABASE_HOST = '' DATABASE_PORT = ''
  3. 3. rails mysite /config/database.yml development: adapter: mysql encoding: utf8 database: mysite_db username: sergio password: qwerty
  4. 4. mysite/ mysite/ __init__.py app/ manage.py controllers/ settings.py helpers/ urls.py models/ views/ config/ manage.py startapp blog db/ doc/ mysite/ lib/ blog/ log/ __init__.py public/ models.py script/ views.py test/ tmp/ vendor/
  5. 5. /db/schema.rb ActiveRecord::Schema.define(:version => 0) do create_table :posts do |t| t.string :title t.text :description t.string :url end end /app/models/post.rb class Post < ActiveRecord::Base belongs_to :user has_many :comments end
  6. 6. /blog/models.py class Post(models.Model): title = models.CharField( max_length=120 ) description = models.TextField() url = models.URLField( verify_exists=True ) user = models.ForeignKey( User ) class Comment(models.Model): ... post = models.ForeignKey( Post, related_name=„comments‟)
  7. 7. class AddDetailsToProducts < ActiveRecord::Migration def self.up add_column :posts, :category, :string end def self.down remove_column :posts, :category end end rake db:migrate
  8. 8. Class Table Inheritance class Person(models.Model): name = models.CharField( max_length=120 ) class Worker( Person ): job = models.CharField( max_length=120 ) class Client( Person ): email = models.EmailField()
  9. 9. /urls.py (r'^blog/(?P<post_id>d+)', blog.views.show_post), /blog/views.py def show_post(request, post_id): post = get_object_or_404(Post, id=post_id) return render_to_response(„blog/post.html', {„post': post})
  10. 10. GENERIC VIEWS /urls.py #Url: /blog/123 (r'^blog/(?P<object_id>d+)', 'django.views.generic.list_detail.object_detail', { 'queryset': Post.objects.all() } ) #Template -> blog/post_detail.html
  11. 11. /app/controllers/blog_controller.rb # URL: /blog/post/123 def post @post = Post.find( params[:id] ) end # Template: /app/views/blog/post.html.erb /config/routes.rb #URL: /blog/123 map.connect „blog/:id‟, :controller => „blog‟, :action => „post‟
  12. 12. /app/views/layouts/blog.html.erb <html><body> <h1> <%= link_to „Blog‟, :controller => „blog‟ %> </h1> <%= yield %> </body></html> /app/views/blog/create.html.erb <% form_for :post, @post, :url => {:action => "create”} do |f| %> <%= f.text_field :title%> <%= f.text_field :description %> <%= submit_tag 'Create' %> <% end %>
  13. 13. /blog/main.html <html> <head> <title> {% block title %}Blog{% endblock %} </title> </head> <body> <h1> <a href=“/blog”>Blog</a> </h1> {% block content %}{% endblock %} </body> </html>
  14. 14. /blog/forms.py Class PostForm(ModelForm): class Meta: model = Post /blog/create.html {% block title %}Create a new post{% endblock %} {% block content %} <form action="/blog/create" method="POST"> {{ form.as_ul }} <input type="submit" value="Submit" /> </form> {% endblock %}
  15. 15. manage.py startapp blog INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'mysite.blog' ) urlpatterns = patterns('', (r'^blog/', include('mysite.blog.urls')), )
  16. 16. Rails::Initializer.run do |config| config.gem "haml" config.gem "chronic", :version => '0.2.3' config.gem "hpricot", :source => http://code.whytheluckystiff.net end ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/restful_authentication/
  17. 17. script/generate controller Blog exists app/controllers/ exists app/helpers/ create app/views/blog > exists test/functional/ > create test/unit/helpers/ create app/controllers/blog_controller.rb > create test/functional/blog_controller_test.rb create app/helpers/blog_helper.rb > create test/unit/helpers/blog_helper_test.rb Rspec, cucumber, shoulda, mocha, webrat...
  18. 18. Doctests def my_func(a_list, index): """ >>> a = ['larry', 'curly', 'moe'] >>> my_func(a, 0) 'larry' >>> my_func(a, 1) 'curly' """ return a_list[index] Unit Tests class MyFuncTestCase(unittest.TestCase): def testBasic(self): a = ['larry', 'curly', 'moe'] self.assertEquals(my_func(a, 0), 'larry') self.assertEquals(my_func(a, 1), 'curly')
  19. 19. Guides.rubyonrails.orgWorking With Rails
  20. 20. • Web applications for information management • Reusable components • Common functionalities built-in - Authentication - Authorization (permissions) - Image or file upload ...
  21. 21. • Less common web applications • AJAX intensive • Dedicated hosting and support • Heavy testing • Specialized tools
  22. 22. Content • http://superjared.com/entry/rails-versus-django/ • http://wiki.alcidesfonseca.com/rails-vs-django/ • http://www.scribd.com/doc/121814/RailsDjango-Comparison • http://docs.google.com/View?docid=dcn8282p_1hg4sr9 • http://www.magpiebrain.com/blog/2005/08/14/a- comparison-of-django-with-rails/
  23. 23. Photos • Title - http://www.flickr.com/photos/dunechaser/2936384537/ • Introduction - http://www.flickr.com/photos/dunechaser/2630433944/ • Disclaimer - http://www.flickr.com/photos/jazamarripae/1936251344/ • Frameworks Background - http://www.flickr.com/photos/albaum/430677776/ • Initial configuration - http://www.flickr.com/photos/somethingstartedcrazyy/1352607255/ • Structure - http://www.flickr.com/photos/9160678@N06/578966742/ • Database & Models - http://www.flickr.com/photos/shindotv/3835365695/ • Controllers/Views - http://www.flickr.com/photos/p1r/633300342/ • Views/Templates - http://www.flickr.com/photos/gigi62/3092670031/ • Administration - http://www.flickr.com/photos/fotopakismo/1183485780/ • Extensibility - http://www.flickr.com/photos/grdloizaga/817443503/ • Testing - http://www.flickr.com/photos/telstar/422117665/ • Communities - http://www.flickr.com/photos/pugetive/506788681/ • Conclusions - http://www.flickr.com/photos/argenberg/188043461/ • Sources - http://www.flickr.com/photos/quarenta/2876309035/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×