Tutorials updated to django 1.4, and its weird new folder structure
As part of my ongoing commitment to the bleeding edge, I've updated all the tutorials to be compatible with Django 1.4.
As I was doing it, I notice that 1.4 has a different folder structure to 1.3 -- it adds an extra "mysite" inside your "mysite" during startproject.
`-- mysite |-- __init__.py |-- manage.py |-- settings.py `-- urls.py
`-- mysite |-- manage.py `-- mysite |-- __init__.py |-- settings.py |-- urls.py `-- wsgi.py
The release notes say that the reason for this is to:
"fix some issues with the previous manage.py handling of Python import paths that caused double imports, trouble moving from development to deployment, and other difficult-to-debug path issues."
When I first saw it I assumed this meant the mysite subfolder would end up containing all project code, thus providing a once-and-for-all answer to the "what's the correct way to import stuff in django" question (ie from myproject.myapp.models import Thing vs from myapp.models import Thing)..
But it turns out that's not the case. The default startapp puts your new app alongside the mysite folder, not inside it... although it will allow you to do either. (read further into https://docs.djangoproject.com/en/dev/releases/1.4/#updated-default-project-layout-and-manage-py)
So you end up with slightly weird project layouts, like this:
|-- database.sqlite |-- fts | |-- __init__.py | |-- test_admin.py | `-- test_polls.py |-- functional_tests.py |-- manage.py |-- mysite | |-- __init__.py | |-- settings_for_fts.py | |-- settings.py | |-- urls.py | `-- wsgi.py `-- polls |-- admin.py |-- forms.py |-- __init__.py |-- models.py |-- templates | |-- home.html | `-- poll.html |-- tests | |-- __init__.py | |-- test_forms.py | |-- test_models.py | `-- test_views.py `-- views.py
And the extra "mysite" folder ends up feeling a little pointless.
I guess it's about whether you really are designing your apps to be portable from one project to another. If it's portable, it goes into the top-level mysite folder, and you do from myapp import Stuff. If it's tied to your project, and not really reusable, you put it inside the sub-level mysite folder, and you do from mysite.myapp import Thing
Anyhoo, check out the new stuff! http://www.tdd-django-tutorial.com/tutorial/1/
PS - had lots of fun with the tree command today! Here's an incantation to get linux tree to exclude .pyc files:
tree -I \*.pyc --charset=ascii