'''
新建一项目
'''
1.django-admin.py startproject name
2.django-admin.py startapp name
'''
同步数据库
登录admin没有表:需在admin.py注册
'''
3.python manage.py syncdb
'''
django1.6.2做了简化,就是很多东西不是注释掉而是没了,用到自己添加
模版路径,默认templates(文件夹名),我给取了views,只好在setting里自己配置了
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), './blog/view/').replace('\','/'),
)
还有static
MEDIA_ROOT = os.path.dirname(__file__)
STATICFILES_DIRS = (
os.path.join(MEDIA_ROOT, 'static/').replace('\','/'),
)
'''
4.403,我把它称为跨域问题,暂时这样解决
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt#每个def都加上一句
def loginhtml(req):
5.urls.py里的正则匹配也是个坑,如果前台用$resource发请求就要小心匹配问题了(其他的不清楚)(500)
6发送请求也是个坑,后台取不到数据(request.body又有数据),我就不多说了
http://victorblog.com/2012/12/20/make-angularjs-http-service-behave-like-jquery-ajax/
自己看吧
headers: {
"content-type":"application/x-www-form-urlencoded;charset=UTF-8"
},
transformRequest:function(obj) {
return $.param(obj);
}
折腾了一天,好不容易搞好了,发现前台拿不到数据(debug里有数据),如果有这种情况,看看有木有new service的情况,没错我就搞了好久,直接使用service即可
searchAPIService.post({login:"login"},user,function(data){
console.info(data);
});
别问我为什么,暂时不知道
7.数据传递用json
8.路径问题很坑,建议统一一个basedir,在setting里
q.前台post ,data:number 后台request.POST.get('one')接收,暂时只知道这种方法
$scope.number={};
$scope.number.one=11
$scope.number.two=22
var number=$scope.number;