Django & Python Adventure Part 1

Django & Python Adventure Part 1

Prenote: If you’re on a MacBook, check out Steve’s walkthrough: http://steveyum.wordpress.com/2011/12/14/learning-django-day-1/

Why Django & Python? Seriously, I don’t need a reason to learn stuff (Codegito Ergo Sum); This one is named after a Jazz Guitarist I like, and that is pretty cool. And the language is named after an awesomely huge snake (okay, he really named it after Monty Python). There is some serious geek power happening here. I’ll have to switch if Nintendo ever releases a Zelda Framework.

Enough philosophy. Here’s what you need to do:
1. Install Python. I choose to go with Python 2.7 over 3. http://www.python.org/getit/
2. Install Django. I choose version 1.3.1 https://www.djangoproject.com/download/ (By install I mean unzip/tar/etc it to C:Django-1.3.1 or something like that)

[Super Important, Often Left Out of Walkthroughs]
Make sure you add python to your system paths! Otherwise nothing works and you’ll be frustrated until you figure that out.
It’s in your Control Panel  System  Advanced system settings (this opens a new window)  Environment Variables
Looks like:
Environment Variables

Drop down to the second section (System Variables) and find the Path and Edit it:
Go to the end and append “;C:Python27” without those quotes. Be really careful not to delete everything in there. You’ll be sad if you do.

Then get to your command line and browse to your PythonXX installation:
Run the Django admin

And type that line.

I’m following along the best rated book I could find on the subject “Django 1.0 Web Site Development”. This is the kind of book I wish I had on a lot of subjects. Not 500 pages of theory that I’m not terribly interested in or reference material that’s available through google.

Django is a Python developed Model-View-Control web framework. This is another big reason I want to learn it. In the Microsoft world, I can create a web application via Web Application, MVC Web Application, and about a dozen other ways. It’s really easy for me to not care about that, since, I’ve already grown accustomed to Web Applications in .Net and the MVC projects really don’t give me anything I don’t already have. So, This is a way for me to see how and why MVC really got big in the first place. Django was created in the bowels of a newsroom where time was essential. That sounds good to me. The MS MVC project I created didn’t really blow me away with the rapidity of anything, so, hopefully this is it.

Anyway, so that line up there generates a folder named after the project:
project folder

Now we’ll configure our database. When you downloaded Python 2.7 (anything 2.5 and up) it loads up SQLLite for you.
As far as Editors are concerned I went with PyCharm 2.0 Beta since it looks a lot like Visual Studio and is free (since it’s in Beta).
You can get PyCharm here:

Now that you’ve got it, open your project folder and edit the settings.py
PyCharm

I wanted to turn on SQLLite and create a database called bookmarksdb.
Looks like this:
DATABASES = {
‘default’: {
‘ENGINE’: ‘sqlite3’, # Add ‘postgresql_psycopg2’, ‘postgresql’, ‘mysql’, ‘sqlite3’ or ‘oracle’.
‘NAME’: ‘bookmarksdb’, # Or path to database file if using sqlite3.
‘USER’: ”, # Not used with sqlite3.
‘PASSWORD’: ”, # Not used with sqlite3.
‘HOST’: ”, # Set to empty string for localhost. Not used with sqlite3.
‘PORT’: ”, # Set to empty string for default. Not used with sqlite3.
}
}

Then I need to get back on the console, browse to the project folder, and execute the command:
database setup

Then you’ll create a superuser for your database and that’s it.
Time to start the server:

Run this command:
Python manage.py runserver
This will start up django’s built in web server. Notice the default port is 8000. One nice thing is that the server restarts every time you modify the code, so, geaerd for easy debugging.
django project startup page

Well that’s enough for a part 1. If you have any questions or comments, shoot me an email.
-Mike

Resources:
Django Website Development 1.0
Python
Django
PyCharm

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

2 Responses to Django & Python Adventure Part 1

  1. steveyum says:

    Hey, good post. Seems like we’re trying to accomplish the same thing but from a different sides of the coin.
    I’ve been dabbling with Django on the Mac. So, this is how you do it on Windows…
    I’ll be sure to read through your whole series, and I’d like to link you from my postings, if you don’t mind.

  2. Pingback: Learning Django (day 2) « Steve's Blog

Leave a Reply

Your email address will not be published. Required fields are marked *