* ubuntu建立虛擬環(huán)境virtualenv(步驟1-4)
* 安裝Django(步驟5-8)
* 開發(fā)學習筆記項目(待定...)
1.建立項目目錄
wilson@ubuntu:~$ mkdir learning_log/
wilson@ubuntu:~$ cd learning_log/
wilson@ubuntu:~/learning_log$
2.安裝virtualenv
因為使用的是ubuntu系統(tǒng)
wilson@ubuntu:~/learning_log$ sudo apt-get install python-virtualenv
3.在第一步創(chuàng)建的項目目錄中創(chuàng)建虛擬環(huán)境
wilson@ubuntu:~/learning_log$ virtualenv ll_env --python=python3
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/wilson/learning_log/ll_env/bin/python3
Also creating executable in /home/wilson/learning_log/ll_env/bin/python
Installing setuptools, pip, wheel...done.
wilson@ubuntu:~/learning_log$
提示如果覺得 ll_env 這個命名不好聽,可以在項目目錄下執(zhí)行
wilson@ubuntu:~/learning_log$ rm -r ll-env
4.激活
wilson@ubuntu:~/learning_log$ source ll_env/bin/activate
(ll_env) wilson@ubuntu:~/learning_log$
如果要停止使用虛擬環(huán)境
(ll_env) wilson@ubuntu:~/learning_log$ deactivate
wilson@ubuntu:~/learning_log$
5.接下來可以在激活的狀態(tài)下安裝Django
(ll_env) wilson@ubuntu:~/learning_log$ pip3 install Django
Collecting Django
Downloading Django-2.0.1-py3-none-any.whl (7.1MB)
100% |████████████████████████████████| 7.1MB 190kB/s
Collecting pytz (from Django)
Downloading pytz-2017.3-py2.py3-none-any.whl (511kB)
100% |████████████████████████████████| 512kB 1.4MB/s
Installing collected packages: pytz, Django
Successfully installed Django-2.0.1 pytz-2017.3
6.創(chuàng)建項目骨架
(ll_env) wilson@ubuntu:~/learning_log$ django-admin.py startproject learning_log .
(ll_env) wilson@ubuntu:~/learning_log$ ls
learning_log ll_env manage.py
(ll_env) wilson@ubuntu:~/learning_log$ ls learning_log/
init.py settings.py urls.py wsgi.py
(ll_env) wilson@ubuntu:~/learning_log$
7.創(chuàng)建數(shù)據(jù)庫
(ll_env) wilson@ubuntu:~/learning_log$ python3 manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying sessions.0001_initial... OK
(ll_env) wilson@ubuntu:~/learning_log$
(ll_env) wilson@ubuntu:~/learning_log$ ls
db.sqlite3 learning_log ll_env manage.py
(ll_env) wilson@ubuntu:~/learning_log$
8.檢查項目
(ll_env) wilson@ubuntu:~/learning_log$ python3 manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
January 04, 2018 - 12:59:00
Django version 2.0.1, using settings 'learning_log.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.(如果要關閉服務ctrl + c)
超效率備注:8000晌姚,因為默認就是8000端口所以可以省略,但是如果啟用后發(fā)現(xiàn)8000端口被占用可有使用python3 manage.py runserver 8001寒屯,這里8001是筆者隨意設定的,大家可以看情況而定浪秘!