Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.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
Python Django主页400调试=False时_Python_Django_Http Status Code 400 - Fatal编程技术网

Python Django主页400调试=False时

Python Django主页400调试=False时,python,django,http-status-code-400,Python,Django,Http Status Code 400,因此,当Debug=True时,我的应用程序在开发服务器上运行良好,然而,当我将其切换为False时,我的主页将返回400。我有一些返回json的端点,无论调试值如何,它们都可以正常工作 我正在使用Django 1.10.2 url.py from django.conf.urls import url from django.contrib import admin from fim_table import views urlpatterns = [ url(r'^$', v

因此,当Debug=True时,我的应用程序在开发服务器上运行良好,然而,当我将其切换为False时,我的主页将返回400。我有一些返回json的端点,无论调试值如何,它们都可以正常工作

我正在使用Django 1.10.2

url.py

from django.conf.urls import url 
from django.contrib import admin
from fim_table import views


urlpatterns = [ 
    url(r'^$', views.create_home),
    url(r'^data/', views.data),
    ...
]
views.py

from django.shortcuts import render
from django.views.decorators.csrf import csrf_protect
from lockdown.decorators import lockdown
from .models import Fim, FimDeleted
from django.http import HttpResponse
from django.db.models.functions import Lower
from django.template.context_processors import csrf
import json


@csrf_protect
def create_home(request):
    return render(request, 'table.html', {'csrf': csrf})


# returns all of the data, unfiltered/response is json
@csrf_protect
def data(request):
    # show distinct names only
    fims = Fim.objects.annotate(name_lower=Lower('crib_name')).order_by('name_lower').distinct('name_lower')
    # fims need to be not a queryset but an array of dicts to be json
    dictionaries = [ idToString(name.as_dict()) for name in fims ]
    mydata = {"aaData": dictionaries}
    return HttpResponse(json.dumps(mydata), content_type='application/json')
设置.py

DEBUG = False
ALLOWED_HOSTS = ["*"]
更新 我实现了一些日志记录,并得到:

连接路径(/DataTables/DataTables.min.css)位于基本路径组件(/Users/me/development/my_project/myapp/staticfiles)之外


我认为这是一个白噪声问题,尽管我设置了settings.py,就像在他们的

中一样,请尝试在“允许的主机”部分添加主机名

For Ex: ALLOWED_HOSTS = ['localhost', 'localhost_projectname', 'server_hostname']
您可以在给定的博客文章中找到更多关于如何在站点中添加404和500页的详细信息


日志中没有任何内容?
[21/Nov/2016 21:46:36]“GET/HTTP/1.1”500 27
是错误500,而不是错误400。无论哪种方式,您都应该启用更多日志记录,以便获得实际的异常。请尝试查看web服务器错误日志,而不是访问日志。我更改了一些内容以获得
500
错误。现在日志正确地显示了我的
400
错误,我已经用一些日志信息更新了我的问题