Archive

Posts Tagged ‘Django’

Setup Django

April 25, 2012 Leave a comment

OK, here’s the simplest way/setting for Django. I am using mac, but it should be similar for other linux.

First. Installing an official release.

  1. Download the latest release from download page.
  2. Untar the downloaded file (e.g. tar xzvf Django-X.Y.tar.gz, where X.Y is the version number of the latest release).
  3. Change into the directory created in step 2 (e.g. cd Django-X.Y).
  4. If you’re using Linux, Mac OS X or some other flavor of Unix, enter the command sudo python setup.py install at the shell prompt.

After install it, run python in the command line, and check:

import django
print django.get_version()

Second,  is to Configure your database and create your first app.

From the command line, cd into a directory where you’d like to store your code, then run the following command:

django-admin.py startproject mysite
Since you install it through command line, ‘django-admin.py’ should be in your system path. If you can not find it, try to find it in site-packages/django/bin, where site-packages is a directory within your Python installation. Consider symlinking to django-admin.py from some place on your path, such as /usr/local/bin.
The above command will create your first site like this:
mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py

Now run the server by doing:

python manage.py runserver.

You will see somthing like this in your terminal:

Validating models...
0 errors found.Django version 1.4, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
 goto http://127.0.0.1:8000/,  cool, it works.  Please also note that MAC actually comes with a embedded Apache Server, you may like to check in details here.
Now you needs to configure you database. Edit mysite/settings.py. To make it as simple as possible, use sqlite3 ( it goes with python, so you don’t have to install additional packages) Change the ENGINE from ‘django.db.backends.‘ to ‘django.db.backends.sqlite3‘.
OK, you are now ready for creating your own models 🙂
Categories: Python, Web Tags: ,