一:安裝python,安裝django,使用虛擬環(huán)境 Virtualenv
[python3的安裝方法]:
http://blog.csdn.net/xudailong_blog/article/details/78309857
[django的安裝方法]:
pip install django==1.10.6(指定版本,如果不進(jìn)行指定的話為最新的,現(xiàn)在最新打為1.11.6)
[虛擬環(huán)境 Virtualenv]
當(dāng)然,這里我暫時沒有用到
二:運行django項目
1 . 新建一個project目錄
注釋:因為我這里之前已經(jīng)創(chuàng)建一個blogproject
的文件了,并且里面也是有django
項目,我先創(chuàng)建打文件djangoblog
然后cd
進(jìn)去,再運行命令:django-admin startproject blogproject
創(chuàng)建了一個blogproject
的項目,我們使用tree
看下目錄結(jié)構(gòu),其中這就是django的目錄結(jié)構(gòu),然后我們運行django項目:
python manage.py runserver
snakeson@snakeson-Inspiron-5421:~/developer/django/djangoblog$ cd blogproject
snakeson@snakeson-Inspiron-5421:~/developer/django/djangoblog/blogproject$ ls
blogproject manage.py
snakeson@snakeson-Inspiron-5421:~/developer/django/djangoblog/blogproject$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
October 29, 2017 - 14:59:33
Django version 1.10.6, using settings 'blogproject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
這里告訴我們需要python manage.py migrate
這里的意思是需要數(shù)據(jù)庫進(jìn)行同步一下的意思,這里可以看下自學(xué)課堂里面的內(nèi)容.有說的,
那我們進(jìn)行運行一下:
python manage.py migrate
出現(xiàn)了這個界面:
snakeson@snakeson-Inspiron-5421:~/developer/django/djangoblog/blogproject$ python 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 sessions.0001_initial... OK
snakeson@snakeson-Inspiron-5421:~/developer/django/djangoblog/blogproject$
我們再運行一下:python manage.py runserver
這樣就ok了:
1 通過網(wǎng)頁打開:127.0.0.1:8080
1 將django 中文化:
需要在settings.py 下找到
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
改為:
LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'