Articles of django

Ubuntu语言环境对Python应用程序不正确

我在Amazon EC2的Ubuntu AMI上安装了NGINX – > UWSGI – > Django(python)堆栈。 访问名称中包含unicode字符的文件时遇到问题。 Django App(Mezzanine)的确切输出是 尝试访问包含path中的Unicode字符的文件,但不知何故当前的语言环境不支持utf-8。 您可能需要将“LC_ALL”设置为正确的值,例如:'en_US.UTF-8'。 现在,当我运行locale命令输出是: LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=en_US.UTF-8 对我来说,一切都看起来不错,所以接下来我添加了一些代码来打印出生成错误的代码段中的语言环境设置。 其结果是: locale.getdefaultlocale() = (None, None) locale.getpreferredencoding() = 'ANSI_X3.4-1968' sys.getdefaultencoding() = 'ascii' sys.getfilesystemencoding() = 'ANSI_X3.4-1968' 所以这看起来不正确,但我不知道如何解决它。 当我在python shell中运行相同的代码时,一切看起来好多了。 locale.getdefaultlocale() = ('en_US', 'UTF-8') locale.getpreferredencoding() = 'UTF-8' […]

正常重启Apache强制重新加载由mod_wsgi处理的所有python模块?

如果我想确保所有的python模块都重新编译,并在我的Django项目下mod_wsgi和Apache重新加载,是否足以重新启动Apache适度地与: /etc/init.d/apache graceful 或者我应该总是使用完整的重新启动 /etc/init.d/apache restart ?

上游超时(110:连接超时),从上游读取响应头

出于某种原因,每当我在服务器上运行查询时,我都会收到此错误。 在我的本地设置,这个查询需要大约7-8秒才能返回,但它保持超时在我的实际服务器上。 错误: 2014/03/26 13:40:13 [error] 11084#0: *22 upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxxxx, server: xxxx request: "GET /xxxxx/ HTTP/1.1", upstream: "uwsgi://unix:///srv/www/poka/app/poka/nginx/poka.sock", host: "xxxx" 2014/03/26 13:41:26 [error] 11084#0: *80 upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxxxx, server: xxx, […]

如何在CentOS上使用uWsgi和nginx来部署django

我的Django版本是1.6.3 我下载了uwsgi-2.0.4。 有人说使用命令安装uwsgi make有人使用python setup.py构build。 究竟是什么区别? 我看到一个教程,说创build一个名为django_wsgi.py的python文件,但我已经在我的django项目中有一个wsgi.py。 它使我困惑不已。 Django_wsgi,uWsgi,wsgi ….有什么区别和function? 然后我想testinguwsgi是否正常工作,所以我写了一个test.py: # test.py def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return "Hello World" 我执行它 uwsgi –http :8001 –wsgi-file test.py 但错误会失败 uwsgi: unrecognized option '–http:8001' 我该如何解决?

Apache不提供我的Python应用程序

所以这里是我的Apacheconfiguration: LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so <VirtualHost *:80> ServerAdmin [email protected] ServerName 31.220.49.197 WSGIDaemonProcess ts threads=25 WSGIProcessGroup ts Alias /static /home/email-validator/static WSGIScriptAlias / /home/email-validator/index.wsgi # Set access permission <Directory /> Allow from all Require all granted </Directory> </VirtualHost> 这是我的index.wsgi: import os import sys import site # Add the app's directory to the PYTHONPATH sys.path.append('/home/email-validator') sys.path.append('/home/email-validator/email_validator') os.environ['DJANGO_SETTINGS_MODULE'] = 'email_validator.settings' […]

如何在sasl支持下在Openshift上安装libmemcached?

我需要带有sasl支持的libmemcached在Openshift Online上使用Memcached Cloud盒式磁带。 我在旁边做: 1)安装sasl。 curl -LO ftp://ftp.cyrusimap.org/cyrus-sasl/cyrus-sasl-2.1.26.tar.gz tar –xvzf cyrus-sasl-2.1.26.tar.gz cd cyrus-sasl-2.1.26 sh configure –prefix=${OPENSHIFT_DATA_DIR}sasl make make install 2)设置envvariables( 更新:添加“&&导出SASL_PATH”): SASL_PATH = ${OPENSHIFT_DATA_DIR}sasl/lib/sasl2 && export SASL_PATH LD_LIBRARY_PATH=${OPENSHIFT_DATA_DIR}sasl/lib/sasl2/:${LD_LIBRARY_PATH} && export LD_LIBRARY_PATH 3)安装libmemcached curl -L -O https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz tar -xvzf libmemcached-1.0.18.tar.gz cd libmemcached-1.0.18 sh configure –prefix=${OPENSHIFT_DATA_DIR}libmemcached –enable-sasl configuration的结果告诉我: sasl支持:不 但是当我在本地机器上安装时,一切都很好。 也许我应该通过萨斯路,但如何做到这一点? 请帮帮我。

Nginx:502错误的网关错误(111:连接被拒绝)到uWSGI套接字,同时运行Django

我正在使用Nginx,uWSGI,Django和Postgresql堆栈构build应用程序。 该应用程序在Nginx和uWSGI之间使用Unix套接字。 在套接字上的文件权限是775.但我仍然得到这个权限错误: [error] 6978#0: *6725 connect() to unix:/path/to/socket failed (111: Connection refused) while connecting to upstream, client: 54.250.253.225, server: example.com, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/path/to/socket:", host: "example.com" Nginxconfiguration # uWSGI upstream upstream app{ server unix:/path/to/socket; } # redirect www to non-www server{ listen 80; server_name www.example.com; return 301 http://example.com$request_uri; } # configuration of […]

解决静态资产的nginxcaching问题

我有一个Django网站,用户发布整个社区的图像(有点像9gag)。 我使用Azure存储来保存和提供图像。 networking服务器是一个nginx反向代理+ gunicorn鸡尾酒。 Gzip启动并运行在我的网站上此外,为了caching静态资产,我在我的nginx conf文件中有以下内容: location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { root /home/mhb11/project/myproject; expires 24h; add_header Vary Accept-Encoding; access_log off; } 我的问题是,当我使用Google Page Speed插件testing我的网站时,我被告知没有任何来自Azure存储的图像被caching: 我该如何为这些caching启用? 请指教。 我对此很新,所以现阶段的任何帮助都会有很大的帮助。 在此先感谢,并有一个愉快的周末。 下面是我自定义存储类的def _save方法,上传一个blob: def _save(self,name,content): blob_service = BlobService(account_name=accountName, account_key=accountKey) import mimetypes small_content = content content.open() content_type = None if hasattr(content.file, 'content_type'): content_type = content.file.content_type else: content_type = mimetypes.guess_type(name)[0] content_str […]

从POST reuqest到django vai WSGI和apache的HTTP 500错误

我有一个Django的web应用程序安装与ubuntu 9.10 mod_wsgi和apache2 即时通讯使用下面的代码来通过一个HTTPpost用户身份validation我的网站的另一部分。 所有它需要的是一个HTTP 200。 from django.contrib.auth import authenticate from django.http import HttpResponse def post_authentication_api(request): if request.method == 'POST': print request user = authenticate(username=request.POST['user'], password=request.POST['pass']) if user is not None: if user.is_active: print "correct" return HttpResponse("correct", mimetype="text/plain") else: print "disabled" return HttpResponse("disabled", mimetype="text/plain", status=401) else: print "incorrect" return HttpResponse("incorrect", mimetype="text/plain", status=401) 这一切工作正常,当我运行它使用python manage.py runserver命令和其他应用程序validation正常。 […]

在Djano中,为什么浏览时得到一个500服务器错误,但从SSH的“python mysite.fcgi”工作正常?

如果我浏览到我的网站,我得到一个500“内部服务器错误”。 但是,如果我SSH到我的服务器,并进入我的网站的文件夹,并运行“python mysite.fcgi”,我看到HTML呈现良好。 显然,有些事情是错的,但我不知道是什么。 这是我的.htaccess文件: AddHandler fastcgi-script .fcgi RewriteEngine On RewriteRule ^(media/.*)$ – [L] RewriteRule ^(static/.*)$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L] 这是我的mysite.fcgi文件: #!/usr/bin/python2.5 import sys, os sys.path.insert(0, "/kunden/homepages/34/[mydir]/htdocs/projects/django") sys.path.insert(1, "/kunden/homepages/34/[mydir]/lib/python/site-packages") os.chdir("/kunden/homepages/34/[mydir]/htdocs/projects/django/mysite") os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' from django.core.servers.fastcgi import runfastcgi runfastcgi(["method=threaded", "daemonize=false"]) 我正在设置1和1。 这是一个痛苦,但我认为我很接近。