This is not yet another Django vs Rails blog post. It is a compilation of notes I made working with Django after having worked on Rails for years.
In this post I want to give a brief introduction to Django project layout from a Rails developer point of view, on what is there, what is not there and where to look for things. It should help a rails developer working on django be able to find the necessary files and underatnd the layout of the project files.
Once you have both the frameworks installed on your system you can create the projects using the commands
# creating a rails project
rails rails_project
# creating a Django project
django-admin.py startproject django_project
Lets look at the files and structure created by the respective frameworks
#rails_project
README
Rakefile
app/
controllers/
application_controller.rb
helpers/
application_helper.rb
models/
views/
layouts/
config/
boot.rb
database.yml
environment.rb
environments/
development.rb
production.rb
test.rb
initializers/
backtrace_silencers.rb
inflections.rb
mime_types.rb
new_rails_defaults.rb
session_store.rb
locales/
en.yml
routes.rb
db/
seeds.rb
doc/
README_FOR_APP
lib/
tasks/
log/
development.log
production.log
server.log
test.log
public/
404.html
422.html
500.html
favicon.ico
images/
rails.png
index.html
javascripts/
application.js
controls.js
dragdrop.js
effects.js
prototype.js
robots.txt
stylesheets/
script/
about
console
dbconsole
destroy
generate
performance/
benchmarker
profiler
plugin
runner
server
test/
fixtures/
functional/
integration/
performance/
browsing_test.rb
test_helper.rb
unit/
tmp/
cache/
pids/
sessions/
sockets/
vendor/
plugins/
that is huge….
lets look at the django project files
# django_project
__init__.py
manage.py
settings.py
urls.py
far lesser when compared to the rails project.
In fact a rails project comes with everything a web application needs. When I say everything I mean everything….. base application, routing, database configuration, development, test and production environment specific configurations and their respective log files, javascript, test, some standard html files and some helpful scripts for developing.
Why then does a Django project have so less number of files? It has got to do with the Django’s philosophy and the concept of applications. The django project is not complete without the application, so lets create a application inside the project and have a look at the structure
django-admin.py startapp app
# django_project
__init__.py
app/
__init__.py
models.py
tests.py
views.py
manage.py
settings.py
urls.py
even after including this, the number of files is still less than the rails project.
Lets break it down and relate both the frameworks.
| Rails | Django | |
|---|---|---|
| Configuration Files |
|
settings.py, one file for everything, database configuration and any other configuaration or settings will be in this file |
| URLs | config/routes.rb | urls.py |
| Schema/Models |
|
|
| Management Commands |
|
manage.py is the file for all your tasks
|
| Application Code | app/controllers/* will contain the application logic | views.py file under each application folder is the place to write to your application logic, file can be named with any name, views.py is the general convention |
| Application templates |
app/views/ |
|
and lets have a look at the other things in rails_project
- Logging, unders the logs directory
- Some default html files for some standard http errors, under the public directory
- Rails has very good support for testing, for that bunch of files under tests
- Vendor/Plugin, place for some third party plugins/applications.
Missing pieces in Django (for a rails developer)
- Scaffold magic
- Generate commands
- Migrations
and what is Django is providing by default? Sorry no extra files in the project; but you will get an authentication system and Django’s killer feature, admin, just by modifying your ‘INSTALLED_APPS’ in your settings. It is similar to the plugins feature in Rails, Django’s philosophy of resusable apps helps you in getting any particular functionality into your project.
Following is a list of what I like in Django (and associated apps):
Following are the questions that I keep getting,
let me know via comments, if you have any answers
program used for listing the files in a directory
import os
import sys
try:
directory = sys.argv[1]
except IndexError:
directory = os.path.dirname(os.path.abspath(__file__))
def r_list_dir(directory, indent=0):
dir_files = sorted([os.path.join(directory, file_name) for file_name in os.listdir(directory)])
for item in dir_files:
if os.path.isdir(item):
print " " * indent + os.path.split(item)[1] + '/'
r_list_dir(item, indent+4)
else:
print " " * indent + os.path.split(item)[1]
r_list_dir(directory)
Related posts:

{ 6 trackbacks }
{ 93 comments… read them below or add one }
← Previous Comments
Django for a Rails Developer — The Usware Blog – Django Web Development http://bit.ly/4UmIEh
This comment was originally posted on Twitter
Django for a Rails Developer — The Usware Blog – Django Web Development http://bit.ly/61vFTe
This comment was originally posted on Twitter
You’re right that it would be easier if some things were set to a reasonable default.But if you want it right now: create a custom command to do it your way and wrap it in an app that you add to the path. When you start a new project, the first thing you do is add the application to your installed apps and you can use it over and over again.
This comment was originally posted on Hacker News
I work with Django for a living but the lack of init/buildout in a new project has always driven me a bit nuts, I guess it’s one of my development pet-peeves.I’ve never had project that didn’t need:
- a project-wide templates/ directory- media/[css|img|js] directories- some kind of database setup by default- contrib.admin (well, I created a form mailer once that had no admin)
Django seems to take a "we don’t want to force you to use any particular setup" stance, but the result seems to be to force you to make a bunch of relatively meaningless decisions before you can start writing code. (they could have other reasons, I haven’t looked into it lately)
These days I have a script that does all this, and I know others have written similar scripts as well. It just strikes me as being a gaping hole on the Django development model… IMO anyway.
This comment was originally posted on Hacker News
The question is, why use the framework to create the layout of project which happens to depend upon that framework at all? Instead, use a generic project templating tool to create the layout, then it’s easy to choose alternate starting points depending upon what you need in your project. In Python, ‘paster’ is commonly used for this. It lets you create projects that depend upon TurboGears or Zope or Plone or Grok or even plain old Python projects which don’t depend upon a full framework.
This comment was originally posted on Hacker News
Also note that the default Django template is showing it’s age. I don’t think it’s ever been updated and it contains a few faux-pas to look out for. In particular, it starts you off inside a python package (__init__.py file), which is highly confusing. If you later want to treat your Django project as a normal Python project, you need to create a setup.py file. But this file would be one directory up from the project directory … which is outside of your Django project. Django puts the directory one level up on your PYTHONPATH to compensate for this, with the assumption that part of your project lives outside of version-control, etc. The solution is to remember to put the directory above the directory that the project lives in version-control and treat it as part of the project. Although then you have to put a library location on your PATH to run the manage.py commands, since this file won’t work if placed in your projects /bin directory.(Speaking of /bin directories, it’s always bugged me that Rails renamed this directory to /scripts … if it’s executable, it goes in /bin, it makes no sense to split executables based on arbitrary implementation details)
This comment was originally posted on Hacker News
I went from django to rails and ruby. I still use python a lot and contribute a little to python open source projects, but I prefer ruby and the ruby frameworks for web development. On top of that, the widespread attitude in the django community that’s the source of comments like yours ensures that I will absolutely never go near django again.
This comment was originally posted on Hacker News
I went from django to rails and ruby. I still use python a lot and contribute a little to python open source projects, but I prefer ruby and the ruby frameworks for web development. On top of that, the widespread attitude in the django community that you’re demonstrating ensures that I will absolutely never go near django again.
This comment was originally posted on Hacker News
I went from django to rails and ruby. I still use python a lot and contribute a little to python open source projects, but I prefer ruby and the ruby frameworks for web development. On top of that, the widespread attitude in the django community that you’re demonstrating ensures that I, for one, will absolutely never go near django again.
This comment was originally posted on Hacker News
http://tinyurl.com/yf8b95b
Django for a Rails Developer — The Usware Blog – Django Web Development
This comment was originally posted on Twitter
Sometimes I wonder if they renamed the pattern just to keep up the music theme…
This comment was originally posted on Hacker News
And your script probably sets things up differently from everyone else’s
But if you think it’s a problem, why not publish whatever you use and encourage others to use it as well?
(also, FWIW I don’t have such a script — a new site at work always simply inherits default settings from other stuff, and those defaults are set up to match how our production servers work)
This comment was originally posted on Hacker News
Well, to be perfectly honest I almost never use the ’startproject’ or ’startapp’ commands. When I’m working on a new app I just create the directory and an __init__.py, and then start filling in specific files inside it as I need them.For stuff at work apps all go into one of a couple particular namespaces, so packaging concerns don’t come up there; for my personal stuff the package name is almost never the same as the app anyway (e.g., django-registration provides an app in a module named ‘registration’).
Also, I’d really really like the concept of the project to die soon.
This comment was originally posted on Hacker News
Django for a Rails Developer http://bit.ly/5KZh6o
This comment was originally posted on Twitter
Seems like Django is more comparable to Sinatra? And is 4 spaces the python way? I like my font big and my lines short.
This comment was originally posted on Hacker News
Django for a Rails Developer — The Usware Blog – Django Web…: Bookmark this on Delicious – Saved by pclaerho.. http://bit.ly/4UmIEh
This comment was originally posted on Twitter
Django for a Rails Developer — The Usware Blog – Django Web Development http://bit.ly/4UmIEh
This comment was originally posted on Twitter
The most annoying part about doing Django as a dev coming from Rails is the RequestContext that isn’t used by default, if you want to access specific contexts like settings. Then it means having to hack it using direct_to_template or writing a decorator.It’s a different philosophy, but it’s hard getting use to having to explicitly spell out everything when I just want to get going with defaults that make sense.
This comment was originally posted on Hacker News
I would also like to see this.
This comment was originally posted on Hacker News
Same here – MTC would have been simpler to understand for me.
This comment was originally posted on Hacker News
> And is 4 spaces the python way?It is, see PEP 8: http://www.python.org/dev/peps/pep-0008/
This comment was originally posted on Hacker News
I admit. I mod up for funny.
This comment was originally posted on Hacker News
> And your script probably sets things up differently from everyone else’s
I don’t doubt it. Much like how there is the occasional "this is how I handle managing multiple settings for different systems" blog post, people have come up with their own systems because Django provides none.
> But if you think it’s a problem, why not publish whatever you use and encourage others to use it as well?
http://github.com/tvon/django-gig
Written for personal use, so…
There is also "create project" or "project template", I forget the exact name, but it’s on bitbucket or github… and "paster" from zopeskel seems to have potential to do something like this but it may be too zope specific, I don’t know.
There are ways to do it, but IMO it’s something the framework should be handling. As it stands, "basic setup and configuration" is a much higher hurdle in Django than it is in Rails.
> (also, FWIW I don’t have such a script — a new site at work always simply inherits default settings from other stuff, and those defaults are set up to match how our production servers work)
Well, you don’t have a script that builds things out in a certain way, but you have a system in place that handles project defaults.
This comment was originally posted on Hacker News
but Google thinks its MVT.http://www.google.com/search?q=django+mvt
http://www.google.com/search?q=django+mtv
This comment was originally posted on Hacker News
Django for a Rails Developer http://tr.im/FTPo http://ff.im/-c4c5c
This comment was originally posted on Twitter
Has anyone seen a "Rails for a Django developer" out there?
This comment was originally posted on Reddit
@nickhammond further to our chat the other day, http://bit.ly/855nIX seems like some useful notes.
This comment was originally posted on Twitter
Django for a Rails Developer http://j.mp/70nLA9
This comment was originally posted on Twitter
Django for a Rails Developer http://bit.ly/6DK4b2
This comment was originally posted on Twitter
Just read that blog post from bottom to top…
This comment was originally posted on Reddit
Django for a Rails Developer http://bit.ly/4JJ0IN
This comment was originally posted on Twitter
Django for a Rails Developer http://j.mp/8nye1l
This comment was originally posted on Twitter
Django for a Rails Developer: Comments http://url4.eu/q5tb
This comment was originally posted on Twitter
Django for a Rails Developer: http://bit.ly/8cb1EU
This comment was originally posted on Twitter
Django for a Rails Developer — The Usware Blog – Django Web: Bookmark this on Delicious – Saved by xiong.chiam.. http://bit.ly/7Gcr8I
This comment was originally posted on Twitter
Django for a Rails Developer http://bit.ly/8j0j7C
This comment was originally posted on Twitter
Django for a Rails Developer http://bit.ly/8EzJW9 #postrank #entrepreneur
This comment was originally posted on Twitter
Actually i would prefer it if models do most of the major work. And views to convert them into a format suitable for presentation. Sometimes that not possible, but it just feels cleaner and more manageable if it is.
This comment was originally posted on Hacker News
Django for a Rails Developer http://icio.us/o2zko5
This comment was originally posted on Twitter
Django for a Rails Developer — The Usware Blog – Django Web Development http://bit.ly/8UKXRP django rails python webdev
This comment was originally posted on Twitter
#django from a #rails developer point of view: http://uswaretech.com/blog/2009/11/django-for-a-rails-developer/
This comment was originally posted on Twitter
very very good document / comparison.
This comment was originally posted on Reddit
Nice non-pejorative rails & django comparison, feature/syntax mapping http://bit.ly/4mS1k1)
This comment was originally posted on Twitter
← Previous Comments