0

我已经启动了一个应用程序来使用tastepie 将数据发布到django。但是,我收到一个 http 403 禁止错误。你能帮我绕过那个错误吗?

编辑: 由于我的views.py,我收到了这个错误

  </script>
            </head>
            <body>
                <div id="summary">
                    <h1>MultiValueDictKeyError at /api/recipes/item_new/</h1>
                    <pre class="exception_value">&#39;Key \&#39;data\&#39; not found in &lt;QueryDict: {u\&#39;{ data:\\n        {\\n          name: &quot;Something&quot;,\\n          content: &quot;Anything&quot;\\n        }\\n}\\n\&#39;: [u\&#39;\&#39;]}&gt;&#39;</pre>
                    <table class="meta">
                        <tr>
                            <th>Request Method:</th>
                            <td>POST</td>
                        </tr>
                        <tr>
                            <th>Request URL:</th>
                            <td>http://localhost:8000/api/recipes/item_new/</td>
                        </tr>
4

2 回答 2

1

您是否遇到 CSRF 错误?您需要将csrf_exempt装饰器添加到您的视图中。

于 2012-08-05T03:19:08.887 回答
0

根据您的 urls.py,您实际上应该为此 url 获得 404/api/recipes/item_new 此外,您的资源已命名recipes,因此您的第一个和第二个 url 是准确的,这意味着第二个永远不会被调用。

url(r'^api/', include(recipe_resource.urls)),
url(r'^api/recipes/$', views.item_new()),

尝试在此处切换订单并调整您的 item_new 网址,如下所示

url(r'^api/recipes/item_new$', views.item_new()),
url(r'^api/', include(recipe_resource.urls)),
于 2012-08-05T00:44:07.733 回答