uwsgi

Django面试题(附带答案)

南楼画角 提交于 2020-01-03 00:01:45
总结的一些Django中会问的问题,希望对你们有用。 1、 Django的生命周期 当用户在浏览器输入url时,浏览器会生成请求头和请求体发送给服务端,url经过Django中的wsgi时请求对象创建完成,经过django的中间件,然后到路由系统匹配路由,匹配成功后走到相对应的views函数,视图函数执行相关的逻辑代码返回执行结果,Django把客户端想要的数据作为一个字符串返回给客户端,客户端接收数据,渲染到页面展现给用户 2、 内置组件 Admin、from、modelfrom、model 3、 缓存方案 设置缓存到内存 缓存到redis,配置redis CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": "redis://39.96.61.39:6379", 'PASSWORD':'19990104.Yu', "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", } } } 单个view缓存 视图导入from django.views.decorators.cache import cache_page 在需要进行缓存的视图函数上添加如下装饰器即可: @cache_page(60 * 2)

Django 的认识,面试题

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 00:01:33
1. 对Django的认识? #1.Django是走大而全的方向,它最出名的是其全自动化的管理后台:只需要使用起ORM,做简单的对象定义,它就能自动生成数据库结构、以及全功能的管理后台。 #2.Django内置的ORM跟框架内的其他模块耦合程度高。 #应用程序必须使用Django内置的ORM,否则就不能享受到框架内提供的种种基于其ORM的便利; #理论上可以切换掉其ORM模块,但这就相当于要把装修完毕的房子拆除重新装修,倒不如一开始就去毛胚房做全新的装修。 #3.Django的卖点是超高的开发效率,其性能扩展有限;采用Django的项目,在流量达到一定规模后,都需要对其进行重构,才能满足性能的要求。 #4.Django适用的是中小型的网站,或者是作为大型网站快速实现产品雏形的工具。 #5.Django模板的设计哲学是彻底的将代码、样式分离; Django从根本上杜绝在模板中进行编码、处理数据的可能。 2. Django 、Flask、Tornado的对比 #1.Django走的是大而全的方向,开发效率高。它的MTV框架,自带的ORM,admin后台管理,自带的sqlite数据库和开发测试用的服务器 #给开发者提高了超高的开发效率 #2.Flask是轻量级的框架,自由,灵活,可扩展性很强,核心基于Werkzeug WSGI工具和jinja2模板引擎 #3

Django面试题

谁说我不能喝 提交于 2020-01-03 00:01:19
Django 的认识,面试题 1. 对Django的认识? #1.Django是走大而全的方向,它最出名的是其全自动化的管理后台:只需要使用起ORM,做简单的对象定义,它就能自动生成数据库结构、以及全功能的管理后台。 #2.Django内置的ORM跟框架内的其他模块耦合程度高。 #应用程序必须使用Django内置的ORM,否则就不能享受到框架内提供的种种基于其ORM的便利; #理论上可以切换掉其ORM模块,但这就相当于要把装修完毕的房子拆除重新装修,倒不如一开始就去毛胚房做全新的装修。 #3.Django的卖点是超高的开发效率,其性能扩展有限;采用Django的项目,在流量达到一定规模后,都需要对其进行重构,才能满足性能的要求。 #4.Django适用的是中小型的网站,或者是作为大型网站快速实现产品雏形的工具。 #5.Django模板的设计哲学是彻底的将代码、样式分离; Django从根本上杜绝在模板中进行编码、处理数据的可能。 2. Django 、Flask、Tornado的对比 #1.Django走的是大而全的方向,开发效率高。它的MTV框架,自带的ORM,admin后台管理,自带的sqlite数据库和开发测试用的服务器 #给开发者提高了超高的开发效率 #2.Flask是轻量级的框架,自由,灵活,可扩展性很强,核心基于Werkzeug WSGI工具和jinja2模板引擎 #3

前后端分离部署

你离开我真会死。 提交于 2020-01-02 21:37:00
部署总体: vue +uwsgi+django+mysql+redis 创建luffy文件夹: [root@localhost opt]# cd luffy 路飞学城django代码下载后端:wget https://files.cnblogs.com/files/pyyu/luffy_boy.zip解压 unzip luffy_boy.zipvue代码下载前端:wget https://files.cnblogs.com/files/pyyu/07-luffy_project_01.zip 创建新的虚拟环境: mkvirtualenv luffy 1.前端vue部署* * vue代码下载:wget https://files.cnblogs.com/files/pyyu/07-luffy_project_01.zip解析:unzip 2.下载node.js wget https://nodejs.org/download/release/v8.6.0/node-v8.6.0-linux-x64.tar.gz 解压:tar -zxvf node-v8.6.0-linux-x64.tar.gz 配置node的环境变量即可 luffy) [root@localhost node-v8.6.0-linux-x64]# cd bin 1.(luffy) [root@localhost

Running a subprocess in uwsgi application

送分小仙女□ 提交于 2020-01-02 10:06:34
问题 I'm writing a Django application, which needs to perform long async tasks. Initial idea was to start a subprocess from the view that does that job, and to monitor the progress in another views. The idea works fine when application is started via manage.py runserver , but it doesn't when it is run under uwsgi. The child process is started, but after the view returns uwsgi waits for the child process end, which breaks the whole idea. I can see the request details in the uwsgi log (number of

uWSGI Emperor Permission Denied unless root

六眼飞鱼酱① 提交于 2020-01-02 08:30:50
问题 I've tried using the flags on the binary itself (--uid www-data --gid www-data) and setting it in my config: uid = www-data gid = www-data but the socket is always spawned with the account I'm working with, so i'm getting a permission denied error from nginx. Anyone know why this is? Additional question: Does anyone know where nginx and uwsgi have the user set? I have another server which has been working forever, and it does not have uid or gid set in any of the config files, yet everything

Nginx is giving uWSGI very old requests?

孤街醉人 提交于 2020-01-01 07:05:26
问题 I'm seeing a weird situation where either Nginx or uwsgi seems to be building up a long queue of incoming requests, and attempting to process them long after the client connection timed out. I'd like to understand and stop that behavior. Here's more info: My Setup My server uses Nginx to pass HTTPS POST requests to uWSGI and Flask via a Unix file socket. I have basically the default configurations on everything. I have a Python client sending 3 requests per second to that server. The Problem

Upload large file nginx + uwsgi

末鹿安然 提交于 2020-01-01 03:20:15
问题 stack: flask 0.10 + uwsgi 1.4.5 + nginx 1.2.3 I can upload small files (<100k) through my application but larger ones fail. uwsgi log shows: Invalid (too big) CONTENT_LENGTH. skip. nginx log does not show anything useful. I tried the following, without success: [nginx conf] client_max_body_size 0 or 20M [uwsgi conf] limit-post: 0 or 20000000 [flask conf] MAX_CONTENT_LENGTH = 20000000 So my questions: Is there a conf somewhere else i can change? Is there a way of verifying the used options at

Linux 下部署Django项目

一曲冷凌霜 提交于 2019-12-31 03:15:42
Linux 下部署Django项目 说明:本文所使用的环境为CentOS 6+Python2.7+Django1.11 安装Django、Nginx和uWSGI 1.确定已经安装了2.7版本的Python; 2.安装python-devel yum install python-devel 3.安装uwsgi pip install uwsgi 测试uwsgi是否能正常工作 1.新建一个index.py; # index.py def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return "Hello World" 1 2 3 4 2.uwsgi –http :8000 –wsgi-file index.py 浏览器访问8000端口看是否有hello world输出 注意:确保8000端口能被外网访问 测试Django能否正常工作 $ cd /var/www/ $ django-admin startproject mysite $ cd mysite $ python manage.py runserver 0.0.0.0:8000 浏览器访问8000端口看是否有hello world输出 测试uwsgi是否能和django集成 uwsgi

2017.07.14 Flask使用80端口服务,Nginx+uWSGI

穿精又带淫゛_ 提交于 2019-12-31 03:15:25
1.操作系统环境:Ubuntu Server 16.04.1 LTS 64位 2.安装前准备: (1)安装 Python 环境 接下来是python , Ubuntu 的默认环境已经预装 python 2.7 所以只需要安装 python 的 pip 安装工具即可。pip 用于安装一些基于python 应用的软件工具,在下文中将会频繁使用。 PIP 如果用python 而不懂 [pip| http://pypi.python.org/ ] 那最好就快点脑补吧, 指令如下: sudo apt-get install pip (2)VirtualEnv 不同的项目可能会引用各种不同的依赖包,为了避免版本与和应用之间的冲突而造成的“依赖地狱” [Virtualenv | https://virtualenv.readthedocs.org/en/latest/ ] 就是我们python 项目的必须品了。VirtualEnv 可以为每个Python应用创建独立的开发环境,使他们互不影响,Virtualenv 能够做到: 在没有权限的情况下安装新套件 不同应用可以使用不同的套件版本 套件升级不影响其他应用 安装: sudo pip install virtualenv (3)安装Nginx 安装并运行Nginx: sudo apt-get install nginx sudo / etc /