Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在nginx下运行django活塞文档时清空文档字符串_Django_Nginx_Markup_Django Piston_Uwsgi - Fatal编程技术网

在nginx下运行django活塞文档时清空文档字符串

在nginx下运行django活塞文档时清空文档字符串,django,nginx,markup,django-piston,uwsgi,Django,Nginx,Markup,Django Piston,Uwsgi,我将django活塞用于REST json api,并通过活塞内置的generate_doc函数将其全部设置为文档。在django runserver下,它工作得非常好。在doc对象上循环的模板成功地列出了类和每个方法的docstring 当我通过nginx和uwsgi为站点提供服务时,docstring是空的。起初,我认为这是django标记过滤器和使用StructuredText格式的问题,但当我关闭它,只是试图查看模板中的原始docstring值时,它们都没有 我在日志中看不到任何问题,我

我将django活塞用于REST json api,并通过活塞内置的generate_doc函数将其全部设置为文档。在django runserver下,它工作得非常好。在doc对象上循环的模板成功地列出了类和每个方法的docstring

当我通过nginx和uwsgi为站点提供服务时,docstring是空的。起初,我认为这是django标记过滤器和使用StructuredText格式的问题,但当我关闭它,只是试图查看模板中的原始docstring值时,它们都没有

我在日志中看不到任何问题,我也不明白为什么nginx/uwsgi是这里的因素,但老实说,它在dev runserver上工作得很好。我一直在想如何通过nginx/uwsgi开始调试它。有没有人遇到过这种情况,或者有人建议我从哪里开始寻找

我的文档视图非常简单:

视图.py

def ApiDoc(request):
    docs = [
        generate_doc(handlers.UsersHandler),
        generate_doc(handlers.CategoryHandler),
    ]

    c = {
        'docs': docs,
        'model': 'Users'
    }

    return render_to_response("api/docs.html", c, RequestContext(request))
我的模板与库存活塞模板几乎相同:

api/docs.html

{% load markup %}

...

    {% for doc in docs %}

        <h5><a href="#top">top</a></h5>
        <h3><a id="{{doc.name}}">{{ doc.name|cut:"Handler" }}:</a></h3>

        <p>
            {{ doc.doc|default:""|restructuredtext }}
        </p>
...
        {% for method in doc.get_all_methods %}

            {% if method.http_name in doc.allowed_methods %}

            <dt><a id="{{doc.name}}_{{method.http_name}}">request</a> <i>{{ method.http_name }}</i></dt>                

            {% if method.doc %}
                <dd>
                    {{ method.doc|default:""|restructuredtext }}
                <dd>
            {% endif %}
我的nginx服务器条目位置代码段如下所示:

已启用站点/mysite.com

server {
    listen 80;
    server_name www.mysite.com mysite.com;

    set $home   /var/www/mysite.com/projects/mysite;
    set $pyhome /var/www/mysite.com/env/mysite;

    root $home;
...
    location ~ ^/(admin|api)/ {
        include uwsgi_params;
        uwsgi_pass uwsgi_main;

        uwsgi_param UWSGI_CHDIR $home;
        uwsgi_param UWSGI_SCRIPT wsgi_app;
        uwsgi_param UWSGI_PYHOME $pyhome;

        expires epoch;
    }
...
}
编辑:配置信息

  • 服务器:Ubuntu 11.04
  • uWSGI版本1.0
  • nginx版本:nginx/1.0.11
  • django非rel 1.3.1
  • django活塞最新pypi 0.2.3
  • python 2.7

    • uWSGI正在以与Python命令行的-OO选项相当的方式启动解释器。第二级优化将删除文档字符串

      -OO    : remove doc-strings in addition to the -O optimizations
      
      更改:

      --optimize 2
      
      致:


      哇!我完全忽略了这一点!很好用!!顺便说一句,我的uwsgi配置是我在网上找到的所有文档的混合体。我还没有完全调查过每一个选项。它更像是其他django/uwsgi设置的推荐配置
      --optimize 2
      
      --optimize 1