随笔分类 -  python_django

django 中cookie的使用
摘要:使用cookie实现一个网页的小功能:在网页浏览器中显示 ' 欢迎 xxx 登录用户 '。 1.写一个简易的表单登录页面。login_cookie.html 2.在views中做判断逻辑。 3. 添加url 4. 登录成功的页面。cookies.html 通过set_cookie()方法设置cook 阅读全文
posted @ 2018-03-22 16:57 hello_xiaoyu 阅读(186) 评论(0) 推荐(0)
python3解决UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
摘要:程序上传到ubuntu服务器本地没有错误,但上传到服务器上出现了UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)的错误。 在python3的环境下查 阅读全文
posted @ 2018-03-07 10:28 hello_xiaoyu 阅读(1273) 评论(0) 推荐(0)
虚拟环境的创建及freeze
摘要:1.创建虚拟环境 pip install virtualenv virtualenv venv3 -p python3 #虚拟环境 虚拟环境的名字 -p python2或者python3的路径。 linux中开启虚拟环境: cd venv3/bin > source activate pip fre 阅读全文
posted @ 2018-03-05 15:44 hello_xiaoyu 阅读(189) 评论(0) 推荐(0)
django+uwsgi+nginx配置及所出问题得解决
摘要:1. django+uwsgi配置 (1) 把django程序上传到服务器。通过python manage.py runserver 运行起来 访问通过服务器的ip地址+端口号访问。例:187.134.123.233:8080 (2)安装uwsgi pip install uwsgi 测试uwsgi 阅读全文
posted @ 2018-02-24 11:14 hello_xiaoyu 阅读(289) 评论(0) 推荐(0)
Django 自定义装饰器 登录验证
摘要:django自定义装饰器: views.py def auth(func): def inner(request,*args,**kwargs): v = request.COOKIES.get('user') #拿到设置得cookie if not v: r = request.path url 阅读全文
posted @ 2018-02-02 16:58 hello_xiaoyu 阅读(347) 评论(0) 推荐(0)
django 基础(常见问题)
摘要:1. 跨域问题: pip install django-cors-headers 在settings中配置: INSTALLED_APPS = [ ... 'corsheaders', ] MIDDLEWARE_CLASSES = ( ... 'corsheaders.middleware.Cors 阅读全文
posted @ 2018-02-02 15:02 hello_xiaoyu 阅读(100) 评论(0) 推荐(0)