Python3 Web开发框架-Django学习笔记(一)搭建项目


python web开发学习心得,原创文章,转载请注明出处

1.建立一个learning_log文件夹,在其中搭建虚拟服务器

2.建立虚拟环境

 ~/Desktop/python/leaning_log ᐅ python -m venv ll_env 
 ~/Desktop/python/leaning_log ᐅ 

使用早期版本Python或系统配置不正确,将不能使用venv模块,可以安装virtualenv包(python3下,pip改为pip3)

 ~/Desktop/python/leaning_log ᐅ  pip install --user virtualenv
 ~/Desktop/python/leaning_log ᐅ virtualenv ll_env
New python executable in ll_env/bin/python Installing setuptools, pip...done. ~/Desktop/python/leaning_log 

2.激活虚拟环境

 ~/Desktop/python/leaning_log ᐅ  source ll_env/bin/activate  
 (ll_env) ~/Desktop/python/leaning_log ᐅ 

3.安装Django

(ll_env) ~/Desktop/python/leaning_log ᐅ pip3 install Django
Collecting Django
  Using cached Django-1.10.6-py2.py3-none-any.whl
Installing collected packages: Django
Successfully installed Django-1.10.6

4.在Django中创建项目(不要忽略 . )

(ll_env) ~/Desktop/python/leaning_log ᐅ django-admin.py startproject leaning_log .
(ll_env) ~/Desktop/python/leaning_log ᐅ ls
leaning_log ll_env      manage.py
(ll_env) ~/Desktop/python/leaning_log ᐅ ls leaning_log
__init__.py settings.py urls.py     wsgi.py

5.创建数据库

(ll_env) ~/Desktop/python/leaning_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 sessions.0001_initial... OK
(ll_env) ~/Desktop/python/leaning_log ᐅ

6.查看项目

(ll_env) ~/Desktop/python/leaning_log ᐅ python3 manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
March 29, 2017 - 05:24:18
Django version 1.10.6, using settings 'leaning_log.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Error: That port is already in use.
(ll_env) ~/Desktop/python/leaning_log ᐅ

遇到错误,Error: That port is already in use.,8000端口已被占用,换个端口8001

(ll_env) ~/Desktop/python/leaning_log ᐅ python3 manage.py runserver 8001
Performing system checks...

System check identified no issues (0 silenced).
March 29, 2017 - 05:25:32
Django version 1.10.6, using settings 'leaning_log.settings'
Starting development server at http://127.0.0.1:8001/
Quit the server with CONTROL-C.

运行结果,在Chrome中访问查看

Python3 Web开发框架-Django学习笔记(一)搭建项目_第1张图片
运行结果

你可能感兴趣的:(Python3 Web开发框架-Django学习笔记(一)搭建项目)