Django

yet another Python Web Framework - heavy MVC mentality

http://www.djangoproject.com/

Oct'2015: at version 1.8.5

Simon Willison was involved along with Adrian Holovaty.


== Links from 2005-2008 ==

http://technorati.com/tags/django

http://www.dehora.net/journal/2005/08/django_debugging_and_mvcp_frameworks.html

http://www.postneo.com/2005/07/18/django-gotchas

key plugins - http://blog.hndigest.com/django-plugins-i-start-my-with/

1100+ "packages" (apps) to leverage. So much redundancy that they have a grid system for evaluating alternatives.

intro implementing a To-Do List.

steps in processing a request

extending its User Model for Web Authentication (2006) (e.g. to add extra fields to the user's profile)


== Starting to play with it - Mar'2009 ==

There's a book-v2 draft in-process that includes django-v1 (book currently in print doesn't cover that version).

Running it on my MacBook, just using SQLite for now.

  • looks like framework code is within '/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django'

Decided it's time to try TextMate.

To run multiple projects, it looks like I set a manual port number when launching like 'python manage.py runserver 8001'.

At first blush, I hate the Template System here as much as with every other one. Though maybe the extra goodies make it worthwhile...

Database chapter

  • doesn't include setup info for SQLite - see v1 book for that (or, duh, just look at the comments in the settings file)

  • missing 'unicode' method for Book class

  • More ORM joys:

    • Unless you instruct it otherwise, Django automatically gives every model an auto-incrementing integer primary key field called id. Each Django model is required to have a single-column primary key.

    • you could swap in SqlAlchemy if you wanted that flavor

    • what if you want to partition your data across [multiple](http://code.djangoproject.com/wiki/Multiple Database Support) databases/servers?

    • what if you want to use a non-SQL Data Store (e.g. like CouchDB, the File System, or Amazon S3) for some of your data?

    • Adding null=True is more complicated than adding blank=True, because null=True changes the semantics of the database - that is, it changes the CREATE TABLE statement to remove the NOT NULL from the publication_date field. To complete this change, we'll need to update the database. For a number of reasons, Django does not attempt to automate changes to database schemas, so it's your own responsibility to execute the appropriate ALTER TABLE statement whenever you make such a change to a model.

Uh, boy, turning on the admin interface created all sorts of issues

  • contrary to docs, it never asked me about creating a superuser

  • then when I hit the '/admin/' url, it told me I needed to uncomment 'django.contrib.contenttypes' in my 'INSTALLED_APPS' list.

  • then when I hit url again, it said "'W S G I Request' object has no attribute 'user'"

  • ok, I also uncommented 'django.contrib.auth', having done 'django.contrib.auth' before; then re-ran syncdb, which then properly had me set up super-user.

  • argh, still getting the "'W S G I Request' object has no attribute 'user'" message

  • I un-commented the 3 'MIDDLEWARE_CLASSES' entries. Now get much messier traceback ending with 'Operational Error: no such table: django_session'

  • So I also uncommented 'django.contrib.sessions', re-ran syncdb, then everything was good.

Apr23'2009: Set up Mac Personal SVN Server before going further.

Apr23 decide to jump into using Pinax, and working on a personal project


Aug'2010 - start building app with Django and MongoDb, so avoiding Pinax for now, but using the VirtualEnv I created there.... Django And Mongodb.

Then decide that's a distraction, and I should focus on the product and stay with the mainstream/core framework.


== start fresh Sept15'2010 ==

start fresh, following docs for 1.2.

  • create director/app inside VirtualEnv pinax-env/mf/

  • launch, hit root, it loads fine

  • edit settings.py file per docs (uncomment admin app line, too). Using SQLite-3. Set db NAME=~/Documents/djcode.../mf/mf.sql

  • run syncdb get sqlite3.Operational Error: unable to open database file

    • used chmod to widen permissions in that directory: no difference

    • tried changing file-extension to .db, then to leave it completely off: no difference

    • changed path to db file to be full (start with /Users/billseitz... instead of ~ - it worked. (Now have mf.db.)

  • as part of syncdb it asked if I wanted to set admin superuser, so I did (and this time I documented it in my Private Wiki).

  • need to start app within the project. It won't let you use the same name for both, so the app is family

Sept26 update: decide to get complicated, and use 2 Data Store-s

  • SQL for users/accounts/payments (make this the "default")

  • Django And Mongodb for everything else

  • hmm, using a tuple of DATABASES entries is for multiple SQL backends. It smells like I keep a single item there for the SQL, and a from mongoengine import connect section for Mongo D B...

  • post to discussion to see if this is kosher.

Outcome: get DayJob, put this on hold.

Mar'2012: come back, decide to stick with straight Django (and SQL): Django For Simplest Thing.

Dec'2013: Jeff Knupp's recommendations for startup up a project the right way. (v 1.6)


Edited:    |       |    Search Twitter for discussion