install django

Refrence: http://fullraith.com/content/788.html

1. Download  tar file from : http://www.djangoproject.com/download/
2. unzip the file and install:
 tar zxvf Django-0.96.tar.gz
 cd Django-0.96
 sudo python setup.py install 
3. Test the django is ok ?
 $yanqing>python
 >>>import django
 // If not throw exception,it ok. In fact, the django is a package of django.

4. Create project: [暫時取名: djangotest,缺省 apache2 的文檔目錄是/var/www.]
 (1). If the django installed, it'll touch file /usr/bin/django-admin.py
 (2). python /usr/bin/django-admin.py startproject gtdcast
 (3). cd gtdcast
   ls
   // it will display the file
   _inti_.py: 表示這是一個 Python 的包
   manage.py: 供簡單化的 django-admin.py 命令,特別是可以自動進行 DJANGO_SETTINGS_MODULES 和 PYTHONPATH 的處理,而沒有這個命令,處理上面環境變量是件麻煩的事情.
   settings.py
   uls.py:  url映射處理文件,而 Django 的url映射是url對於某個模塊方法的映射,目前不能自動完成
 (4). sudo python manage.py runserver:
  /** Validating models...
   0 errors found.

   Django version 0.96.3, using settings 'djangotest.settings'
   Development server is running at http://127.0.0.1:8000/
   Quit the server with CONTROL-C. **/
   
 (5). Visit the http://127.0.0.1:8080/.
 
---------------------------  more ---------------------------------------
5. apached mod_python install:
 (1). sudo apt-get install apache2
 (2). sudo apt-get install libapache2-mod-python2.5
 (3). sudo vi /etc/apache2/site-avaiable/default 添加:
   <Directory /var/www>
    SetHandler python-program
    PythonPath "['/var/www'] + sys.path"
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE djangotest.settings
    PythonDebug On
   </Directory>
 (4). 重啓 apache /etc/init.d/apache2 restart
  
6. 進入 gtdcast 目錄:
 _init_.py: 表示這是一個 Python 的包。
 manage.py: 
 settings.py:
 urls.py: 
 
7. Start server:
  manage.py runserver 
8. 請注意 action 爲 /add/ ,在 Django 中鏈接後面一般都要有 '/' ,不然有可能得不到 POST 數據。有關更詳細的關於常見問題可以參閱 NewbieMistakes 文檔
 http://code.djangoproject.com/wiki/NewbieMistakes
 Django 的設計風格中認爲: 使用 POST ---->,GET----->獲取。
 (URL Dispatcher:http://docs.djangoproject.com/en/dev/topics/http/urls/?from=olddocs)
 
9. 模板系統: 
 (1). def index(request):
      return render_to_response('list.html', {'address': address})
     // Django 0.91 中,模板文件都是以.html結尾的,並且使用時不帶後綴的。但0.95版本取消了模板後綴的設置,因此模板文件名必須是完整的,不再有默認後綴名了。
    (2). Django 還支持在App中定義一個 templates目錄。這樣Django在啓動時會檢查所有安裝的App的templates,如果存在,則將路徑的搜索放在 TEMPLATE_DIRS之後.
    (3). Django模板中{ {} }表示引用一個變量。
        { %% } 表示代碼調用。
     (Built-in template tags and filters: http://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs)
    (4). for in
      {% for user in address %}
       {{ user.name }}
       {{ user.address }}
      <% endfor%>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章