我的环境: Ubuntu14.04 64bit、Python2.7.6、Django1.8.7
环境要求
Python2.7+
查看当前python版本:python --version
Django1.7+
查看Django版本:
命令行中先输入python
,
然后依次输入import django
django.VERSION
然后回车即可看到版本号,Ctrol + D 退出编辑。
注意:千万不要卸载Python3.4!!!
千万不要卸载Python3.4!!!
千万不要卸载Python3.4!!!
由于很多软件关联了python如果卸载了,其他软件也会被自动卸载!!!!
配置ATC
a)安装pip
sudo apt-get install python-pip python-dev build-essential
sudo pip install --upgrade pip
b)然后通过pip安装ATC,必须使用sudo!!
sudo pip install atc_thrift atcd django-atc-api django-atc-demo-ui django-atc-profile-storage
c)安装Django1.8.7,一定要使用sudo!!!
sudo pip install Django==1.8.7
d)现在所有的包都已经安装完成,需要使用Django创建一个应用
django-admin startproject myatcui
cd myatcui
(注意,以后所有操作目录都是myatcui)
e)修改文件:atcui/settings.py,在INSTALLED_APPS的值中加入下面内容
INSTALLED_APPS = (
# Django ATC API
'rest_framework',
'atc_api',
# Django ATC Demo UI
'bootstrap_themes',
'django_static_jquery',
'atc_demo_ui',
# Django ATC Profile Storage
'atc_profile_storage',
)
f)修改文件:atcui/urls.py,第一行必须要加,不要忘记,否则报错;并在urlpatterns中加入如下内容。
from django.views.generic.base import RedirectView
urlpatterns = patterns(
...
# Django ATC API
url(r'^api/v1/', include('atc_api.urls')),
# Django ATC Demo UI
url(r'^atc_demo_ui/', include('atc_demo_ui.urls')),
# Django ATC profile storage
url(r'^api/v1/profiles/', include('atc_profile_storage.urls')),
url(r'^$', RedirectView.as_view(url='/atc_demo_ui/', permanent=False)),
)
g)更新Django数据库
python manage.py migrate
(有些低版本Django中不是migrate而是syncdb)
运行ATC
a)修改网卡的相关设置,这两个命令运行完可以ctrol + C强制结束
sudo atcd --atcd-lan wlan0
(最后参数为无线网卡名称)
sudo atcd --atcd-wan eth0
(最后参数为有线网卡名称)
ifcofig -a(查看网卡信息,可以找到对应网卡名称)
b)启动服务
python manage.py runserver 0.0.0.0:8000
启动成功如上图所示,有连接时出现下面紫色字。可以在PC的浏览器中输入http://localhost:8000 连接服务端
c)Android手机连接服务器
首先PC创建热点,具体参见:
http://blog.youkuaiyun.com/piscesq329a/article/details/48497559
在Android的浏览器中输入http://[ubuntu的内网IP]:8000 连接服务端;比如:http://192.168.1.110:8000
遇见错误
错误一:错误如下,原因atcui/urls.py文件中未添加:from django.views.generic.base import RedirectView
参考链接:
Django官方网站:https://www.djangoproject.com/download/
ATC使用教程:http://www.cnblogs.com/coderzh/p/AugmentedTrafficControl.html
Github-ATC官网:https://github.com/facebook/augmented-traffic-control