2
因此,當Debug = True時,我的應用程序在開發服務器上工作正常,但是當我將它切換爲False時,我的主頁給我返回了400回。我有一些返回json的終結點,它們工作正常,無論調試值如何。Django Homepage 400 debug = False
我使用Django 1.10.2
urls.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')
settings.py
DEBUG = False
ALLOWED_HOSTS = ["*"]
更新 我實現了一些日誌記錄,得到:
連接路徑(/DataTables/datatables.min.css)位於基本路徑組件(/ Users/me/development/my_project/myapp/staticfiles)之外。
我想這是一個白噪聲的問題,即使我建立了我的settings.py酷似它是在被允許的主機部分的docs
在日誌中什麼都沒有? – kichik
'[21/Nov/2016 21:46:36]「GET/HTTP/1.1」500 27'是 – heliotrope
這是錯誤500,而不是錯誤400.無論哪種方式,您應該啓用更多日誌記錄,以便獲得實際的異常。 – kichik