1.Django分页出现UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered ob
将
messeges = MessegeModel.objects.all()
变为
messeges = MessegeModel.objects.get_queryset().order_by('id')
2.ajax提交表单403:
data: {'content':content,"csrfmiddlewaretoken":$("[name='csrfmiddlewaretoken']").val()}
3.ajax返回值未序列化:
1.序列化Quset对象
pictures = AlbumModel.objects.all()
data['pictures'] = serializers.serialize('json', pictures)
return JsonResponse(data)
在js中要进行反序列化的操作:
var formData = new FormData($("#form")[0]);
2.序列化单个实例(model)
user = simplejson.loads(serializers.serialize('json', [user])[1:-1])
4.Specifying a namespace in include() without providing an app_name '
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
这是url
中的`include
的问题,这样写
url(r'^reviews/', include(('reviews.urls', 'reviews'), namespace='reviews'))
5.无法导入模块ImportError: cannot import name 'simplejson'
首先检查pip版本是不是用的python3
的pip3
,因为python3
自带了pip3
,所以可以创建一个pip3
的软连接
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
(我的pip3在/usr/local/python3/bin/pip3,可以通过whereis查看)
4.xshell推出后django后台程序也被关闭
解决方法:
在启动项目的时候nohup python manage.py runserver 0.0.0.0:80
5.更新数据库的数据出现'BlogModel' object has no attribute 'update'
不直接对数据库进行update
操作
current_blog = BlogModel.objects.get(id=blog_id)
current_blog.blog_name = blog_name
current_blog.blog = blog
current_blog.blog1 = blog1
current_blog.save(update_fields=['blog_name','blog','blog1'])