照着教程搭建 django 环境都能失败,伤不起啊。

2015-03-16 15:52:03 +08:00
 jianghu52

照着这个教程搭建 django 环境
[https://github.com/imelucifer/MyNote/blob/master/django/django%2Buwsgi%2Bnginx%2Bcentos部署.md]
安装软件都成功了,单独运行 python manage.py runserver成功。
测试uwsgi 的语句 uwsgi --http :9090 --wsgi-file test.py 也是成功的。
但是当我测试 uwsgi --http :8000 --chdir /root/mysite --module django_wsgi 这句的时候,当我访问
连接的时候,就报错了。

No handlers could be found for logger "django.request"
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    response = self.get_response(request)
  File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 199, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 236, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/usr/local/lib/python2.7/site-packages/django/views/debug.py", line 91, in technical_500_response
    html = reporter.get_traceback_html()
  File "/usr/local/lib/python2.7/site-packages/django/views/debug.py", line 350, in get_traceback_html
    return t.render(c)
  File "/usr/local/lib/python2.7/site-packages/django/template/base.py", line 148, in render
    return self._render(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/base.py", line 142, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/base.py", line 844, in render
    bit = self.render_node(node, context)
  File "/usr/local/lib/python2.7/site-packages/django/template/debug.py", line 80, in render_node
    return node.render(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/debug.py", line 90, in render
    output = self.filter_expression.resolve(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/base.py", line 624, in resolve
    new_obj = func(obj, *arg_vals)
  File "/usr/local/lib/python2.7/site-packages/django/template/defaultfilters.py", line 769, in date
    return format(value, arg)
  File "/usr/local/lib/python2.7/site-packages/django/utils/dateformat.py", line 343, in format
    return df.format(format_string)
  File "/usr/local/lib/python2.7/site-packages/django/utils/dateformat.py", line 35, in format
    pieces.append(force_text(getattr(self, piece)()))
  File "/usr/local/lib/python2.7/site-packages/django/utils/dateformat.py", line 268, in r
    return self.format('D, j M Y H:i:s O')
  File "/usr/local/lib/python2.7/site-packages/django/utils/dateformat.py", line 35, in format
    pieces.append(force_text(getattr(self, piece)()))
  File "/usr/local/lib/python2.7/site-packages/django/utils/encoding.py", line 85, in force_text
    s = six.text_type(s)
  File "/usr/local/lib/python2.7/site-packages/django/utils/functional.py", line 144, in __text_cast
    return func(*self.__args, **self.__kw)
  File "/usr/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 83, in ugettext
    return _trans.ugettext(message)
  File "/usr/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 325, in ugettext
    return do_translate(message, 'ugettext')
  File "/usr/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 306, in do_translate
    _default = translation(settings.LANGUAGE_CODE)
  File "/usr/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 209, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/usr/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 189, in _fetch
    "The translation infrastructure cannot be initialized before the "
django.core.exceptions.AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.
[pid: 15722|app: 0|req: 1/1] 116.3.4.114 () {42 vars in 696 bytes} [Mon Mar 16 07:46:24 2015] GET / => generated 0 bytes in 109 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)

看样子像是我django有问题。但是具体什么问题我就看不出来了。求达人指点
环境
阿里云 centos6.5 64位
python 2.7
django 1.7.6
uwsgi 2.0.9
nginx 1.6.2

6343 次点击
所在节点    Django
22 条回复
syv2
2015-03-16 17:03:17 +08:00
我记得在初始化项目的时候,settings会自动内置几个loggers,其中就包括了django.request。你这里报的这个错,显然是django_uwsgi内起用了日志,但是找不到django.request这个logger。你需要在settings.LOGGING['loggers']中添加一个logger:
'django.request': {'handerls': [], 'level': 'ERROR'}

试试看呢
jianghu52
2015-03-16 17:38:51 +08:00
@syv2 非常感谢。我试试看。
jianghu52
2015-03-16 17:54:42 +08:00
@syv2 不好意思啊。我没找到settings.LOGGING这个文件。你要方便的话,能不能帮我看看实际环境呢。我这个阿里云vps没啥东西,你可以随意操作。
vps:
地址: 120.24.54.91 内网 10.169.140.118
账户 root 密码 Win2008admin

mysql
root mysqladmin
jianghu52
2015-03-16 17:55:15 +08:00
@syv2 django工程我建在/root/mysite 这里了
syv2
2015-03-16 18:12:32 +08:00
我已经帮你在settings中添加了这个logger的定义。
typcn
2015-03-16 18:16:23 +08:00
@jianghu52 赶紧改了密码吧,小小有的人
msg7086
2015-03-16 19:23:43 +08:00
@jianghu52 不要随便贴密码。被人攻占了,一切后果要由你来承担的。搞不好还可能吃官司坐牢。
jianghu52
2015-03-16 19:26:26 +08:00
@msg7086 @syv2 @typcn 谢谢各位了。我马上改密码
loading
2015-03-16 19:48:08 +08:00
楼主实属勇敢,你如何排除这段时间没人去留后门?
建议重新来吧!
jianghu52
2015-03-16 20:00:25 +08:00
只有一个月生命力的玩意儿,真要是有问题。估计还没等爆发,就消失了。
jianghu52
2015-03-16 20:01:10 +08:00
@syv2 谢谢了。不过还是出错。我自己研究下吧。
jun4rui
2015-03-16 20:08:16 +08:00
Django这种框架你要找新的教程,因为这类玩意老变,经常更新版本命令就不同了,例如老的数据库和新的数据库完全不同了。

这还算好的,Rubyonralis变化更加频繁,貌似ralis style的框架都是如此。所以你要做好准备,不要只看老教程,教程要和你安装的官方最新版文档一起看。最新的是1.76,你的教程是1.55,差距不多也不少。

我也是刚开始玩Django,对照着刚刚了解基础架构,
limbo0
2015-03-16 20:38:34 +08:00
ericls
2015-03-17 00:52:37 +08:00
教程的django版本太老了

主要是wsgi那一块。。

以前是:django.core.handlers.wsgi:WSGIHandler()
现在是:PROJECT.wsgi:application
ericls
2015-03-17 00:53:38 +08:00
而且Django最好看的还是官方Tutoria
gevin
2015-03-17 09:05:30 +08:00
看我这篇有没有帮助,我是按这个部署的
http://blog.igevin.info/2014/09/30/deploy-django-with-nginx-and-uwsgi-on-Ubuntu/

文章最上面链接是英文原文,不行就看原文
jianghu52
2015-03-17 09:50:37 +08:00
@gevin 谢谢。我按照这个试试看
flymyhobby
2015-03-17 15:50:51 +08:00
http://blog.igeek.so/uwsgi-django-nginx/ 照着这个来试试,django 1.6肯定没问题
ioth
2015-03-17 18:02:27 +08:00
VERSION = (1, 8, 0, 'alpha', 0)

好像没啥问题。
jianghu52
2015-03-17 20:18:03 +08:00
我现在怀疑是不是因为django配置有什么问题。我在本机模拟装这些个版本的,也是跑不起来,换个django1.6试试看

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/177287

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX