老大说要搞一套demo版的时间表工具让他看看,找了几个方案,他还是中意timesheet,那就开搞吧。之前也没接触过Django,过程中到处是坑啊,还好最后成型了,步骤如下:
一. 安装pip
aptitude install python-pip
二. pip安装依赖的组件
apt-get install python-dateutil pip install django-selectable pip install django-pagination pip install django-compressor pip install django-bootstrap-toolkit aptitude install build-dep libpq-dev apt-get install python-software-properties
三. 增加jessin源,安装相关软件包:
1. 添加源:
vim /etc/apt/souces.list deb http://mirrors.163.com/debian/ jessie main deb-src http://mirrors.163.com/debian/ jessie main deb http://security.debian.org/ jessie/updates main deb-src http://security.debian.org/ jessie/updates main # jessie-updates, previously known as 'volatile' deb http://mirrors.163.com/debian/ jessie-updates main deb-src http://mirrors.163.com/debian/ jessie-updates main # jessie-backports, previously on backports.debian.org deb http://mirrors.163.com/debian/ jessie-backports main deb-src http://mirrors.163.com/debian/ jessie-backports main apt-get update
2.安装Nodejs:
aptitude -t testing install nodejs
创建软链接:
ln -s /usr/bin/js /usr/local/bin/node
3. 安装npm
aptitude -t testing install npm
4. 用npm方式安装less
npm install less -g
5. 安装postgresql
apt-get install postgresql-9.1 apt-get install postgresql-server-dev-9.1
重启postgresql
/etc/init.d/postgresql restart
6. 安装python-dev包
aptitude -t testing install python-dev pip install psycopg2
7. 安装django:
注意django不指定版本的话,默认安装1.6.5,而1.6.5已经移除了hashcompt模块,而timepiece是正好需要这个模块的,因此需要手动将django的默认版本更改到1.4,否则装完也启动不了。在这块捣鼓了我一天时间!
pip install django-timepiece django==1.4
8.获取django-timepiece
下载github上的源码包
网址 https://github.com/caktus/django-timepiece
下载后上传到服务器下,如/home中,解压文件:
cd /home unzip django-timepiece-develop.zip cd django-timepiece-develop
拷贝manage.py脚本到django-timepiece目录下:
cp example_project/manage.py .
拷贝local.py.example到local.py
cd /home/django-timepiece-develop/example_project/settings cp local.py.example local.py
9. 修改pgsql配置文件,创建数据库和用户:
vi /etc/postgresql/9.3/main/pg_hba.conf local all all peer 将peer改为md5
重启pgsql:
/etc/init.d/postgresql restart
创建数据库:
sudo -u postgres createuser -d -P dbuser #创建用户 sudo -u postgres createdb -O dbuser timepiece #使用用户创建数据库
10.修改local.py配置文件:
vim example_project/settings/local.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'timepiece', 'USER': 'dbuser', 'PASSWORD': '123456', 'HOST': '127.0.0.1', 'PORT': '5432', } }
将数据库名字、用户和密码都换成上一步创建的数据库和用户信息,保存退出。
11. 将配置同步到数据库
python manage.py syncdb
同步的时候系统会让你设置一个访问账户的信息,如用户、密码、邮箱等等,自行设置,这个就是登陆账号的信息。
You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes Username (leave blank to use 'root'): dbuser E-mail address: [email protected] Password: Password (again):
完成后会有同步完成的提示。
Superuser created successfully. Installing custom SQL ... Installing indexes ... Installed 0 object(s) from 0 fixture(s)
12. 启动程序:
python manage.py runserver 0.0.0.0:8000
端口可以自己选择一个空闲的端口,0.0.0.0是允许所有地址访问,也可以在后面加入&让其运行在后台。
也可以将访问日志重定向到指定日志文件:
python manage.py runserver 0.0.0.0:8000 >>/var/log/timesheet.log 2>&1 &
0K,打开浏览器开始吧~
本文出自 “DBQ blog” 博客,谢绝转载!