Saturday, February 19, 2011

#1 Setup a basic Django project

, I've been getting more and more interested in Django. I think why shouldn't I write a series about it. So, let's start with the basics first: how to setup Django development environment and build a basic Django project.

1. Setup environments
  • Install Python
       Get Python at http://www.python.org
       To verify if it's already installed, at console:
   $ python
   Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) 
   [GCC 4.4.5] on linux2
   Type "help", "copyright", "credits" or "license" for more information.
  • Install Django
       Download a Django release at http://www.djangoproject.com/download/
   $ tar xzvf Django.tar.gz
   $ cd Django
   $ sudo python setup.py install 

       To verfiy what's your current Django's version
   $ python
   >>> import django
   >>> django.get_version()
    
2. Create a basic Django project 
  • To initialize project 
    $ django-admin.py startproject mysite
          This will create a basic Django project in mysite directory that looks as below
    mysite/
       __init__.py
       manage.py
       settings.py
       urls.py
  • Now run a development webserver to see if your Django site works
    $ python manage.py runserver
    Validating models...
    0 errors found.

    Django version 1.0, 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 on your Web browser, you'll see a "Welcome to Django" page. It's works!
So, you have setup a very basic Django project. If you want to make more complex stuffs, you may need to use a database backend, create some models, build your site's templates, mapping urls to what will process & response the corressponding templates (Django call this "views"), add some caching mechanisms to boost performance,...

No comments: