1. 程式人生 > >Diango安裝及建立專案

Diango安裝及建立專案

安裝Diango

命令: sudo pip install Django
錯誤:

root:bin xianglingchuan$ sudo pip install Django
Password:
Sorry, try again.
Password:
Sorry, try again.
Password:
The directory '/Users/root/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the
permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/Users/root/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with
sudo, you may want sudo's -H flag. Collecting Django Downloading Django-2.0.tar.gz (8.0MB) 100% |████████████████████████████████| 8.0MB 25kB/s Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/tmp/pip-build-fumLES/Django/setup.py"
, line 32, in <module> version = __import__('django').get_version() File "django/__init__.py", line 1, in <module> from django.utils.version import get_version File "django/utils/version.py", line 61, in <module> @functools.lru_cache() AttributeError: 'module' object has no attribute 'lru_cache' ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-fumLES/Django/ root:bin xianglingchuan$ sudo pip install Django==1.9

因為Django與python存在不相容,命令修改為:
sudo pip install Django==1.9

建立專案

django-admin.py startproject dmosite

啟動專案

python manage.py runserver 0.0.0.0:8002

目錄說明:
manage.py: 一個實用的命令列工具,可讓你以各種方式與該 Django 專案進行互動。
demosite/init.py: 一個空檔案,告訴 Python 該目錄是一個 Python 包。
demosite/settings.py: 該 Django 專案的設定/配置。
demosite/urls.py: 該 Django 專案的 URL 宣告; 一份由 Django 驅動的網站”目錄”。
demosite/wsgi.py: 一個 WSGI 相容的 Web 伺服器的入口,以便執行你的專案。