需求分析:
1 博客主页, blog显示
2 单张博客细节展示
3 博客标签新建及归档
4 博客评论系统
5 博客在线编辑系统
6 博客增,删,改,查功能
开发环境
1 install djangopip install django==1.8.82 install mysqlyum install mysql mysql-server mysql-devel -y3 install python-mysqlwget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/downloadtar -zxvf MySQL-python-1.2.3.tar.gz cd MySQL-python-1.2.3python setup.py build python setup.py install
建立新项目myblog
[root@hding django]# django-admin.py startproject myblog[root@hding django]# tree myblog/myblog/|-- manage.py`-- myblog |-- __init__.py |-- settings.py |-- urls.py `-- wsgi.py建立新应用
[root@hding django]# cd myblog/[root@hding myblog]# django-admin.py startapp blogmyblog/|-- blog| |-- __init__.py| |-- admin.py| |-- migrations| | `-- __init__.py| |-- models.py| |-- tests.py| `-- views.py|-- manage.py`-- myblog |-- __init__.py |-- settings.py |-- urls.py `-- wsgi.py新建database blog
[root@hding myblog]# mysql -urootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.0.95 Source distributionCopyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> create database blog default charset utf8; Query OK, 1 row affected (0.00 sec)
编辑settings.py使得连接的数据库由默认的sqlite转为mysql,并且修改app
#myblog/myblog/settings.pyINSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'blog', #新建blog ) DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', #更改默认数据库为mysql 'NAME': 'blog', #数据库名为blog, 这个数据库必需先建好,否则提示错误 } }运行系统
[root@hding myblog]# python manage.py runserver 192.168.2.111:8000Performing system checks...System check identified no issues (0 silenced).You have unapplied migrations; your app may not work properly until they are applied. #数据库建立好后没有同步Run 'python manage.py migrate' to apply them.February 09, 2016 - 15:36:47Django version 1.8.8, using settings 'myblog.settings'Starting development server at http://192.168.2.111:8000/Quit the server with CONTROL-C.
当这个画面出现时,说明django服务器成功搭建