一:安装python,安装django,使用虚拟环境 Virtualenv
[python3的安装方法]:
http://blog.csdn.net/xudailong_blog/article/details/78309857
[django的安装方法]:
pip install django==1.10.6(指定版本,如果不进行指定的话为最新的,现在最新打为1.11.6)
[虚拟环境 Virtualenv]
当然,这里我暂时没有用到
二:运行django项目
1 . 新建一个project目录
注释:因为我这里之前已经创建一个blogproject
的文件了,并且里面也是有django
项目,我先创建打文件djangoblog
然后cd
进去,再运行命令:django-admin startproject blogproject
创建了一个blogproject
的项目,我们使用tree
看下目录结构,其中这就是django的目录结构,然后我们运行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
这里的意思是需要数据库进行同步一下的意思,这里可以看下自学课堂里面的内容.有说的,
那我们进行运行一下:
python manage.py migrate
出现了这个界面:
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 通过网页打开:127.0.0.1:8080
1 将django 中文化:
需要在settings.py 下找到
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
改为:
LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'