我是第一次部署Django App,到目前为止一切都相当顺利。我的网站工作正常,除了一个在本地工作的CreateView(EstRequestCreateView),但当我尝试在生产中创建新的估计请求时,我收到错误请求(500)响应。我已经在代码中添加了一些打印语句,只是为了确定它的失败位置,但它似乎是在幕后的某个地方,因为它使我的两个函数一直没有问题。
这是我的观点:
class EstRequestCreateView(CreateView):
model = EstRequest
# fields = ['market', 'builder', 'plan', 'due_date', 'notes']
form_class = EstRequestModelForm
template_name = 'requests/request_form.html'
success_url = '/requests/'
def post(self, request, *args, **kwargs):
if request.user.is_authenticated():
print(request.POST)
form = self.get_form()
print('form')
if form.is_valid():
print('is_valid')
return self.form_valid(form)
else:
print('not valid')
return self.form_invalid(form)
def form_valid(self, form):
print('form_valid func')
form.instance.added_by = self.request.user
print('user')
market = self.request.POST['market']
print('market')
note = self.request.POST['notes']
print('notes')
due_date = self.request.POST['due_date']
print('duedate')
form.instance.trello_id = create_card(market, note, due_date)
print('trello created')
return super(EstRequestCreateView, self).form_valid(form)
这是我登录Heroku的日志:
Dec 21 15:40:51 ao-prime app/web.1: <QueryDict: {'csrfmiddlewaretoken': ['ympCUozBK7qYEoMHgAffBWCoQce7nrqC'], 'plan': [''], 'due_date': ['2016-12-26 18:40:39'], 'market': ['1'], 'builder': ['1'], 'notes': ['Test 1 with Logging']}>
Dec 21 15:40:51 ao-prime app/web.1: form
Dec 21 15:40:51 ao-prime app/web.1: is_valid
Dec 21 15:40:51 ao-prime app/web.1: form_valid func
Dec 21 15:40:51 ao-prime app/web.1: user
Dec 21 15:40:51 ao-prime app/web.1: market
Dec 21 15:40:51 ao-prime app/web.1: notes
Dec 21 15:40:51 ao-prime app/web.1: duedate
Dec 21 15:40:51 ao-prime app/web.1: creating card
Dec 21 15:40:51 ao-prime app/web.1: getting card values
Dec 21 15:40:51 ao-prime app/web.1: got card values
Dec 21 15:40:51 ao-prime app/web.1: got market
Dec 21 15:40:51 ao-prime app/web.1: params set
Dec 21 15:40:51 ao-prime app/web.1: request
Dec 21 15:40:51 ao-prime app/web.1: json created
Dec 21 15:40:51 ao-prime app/web.1: trello id
Dec 21 15:40:51 ao-prime app/web.1: trello created
Dec 21 15:40:51 ao-prime heroku/router: at=info method=POST path="/requests/create/" host=www.ao-prime.com request_id=8919f0d5-96f9-423f-b6c7-f7f10113368a fwd="74.218.177.46" dyno=web.1 connect=1ms service=483ms status=500 bytes=253
来自Heroku的唯一有用的是响应500.我已经添加了Print语句,以确保我定义的函数至少运行到Return语句。我不确定有什么问题,我不确定如何进一步调试。就像我说的那样,它在Test中完美运行。
有人可以帮我指出我可能错了吗?或者,如果没有帮助我理解我如何调试生产更成功。我尝试将papertrail日志插件添加到我的Heroku应用程序中,但它看起来与我在Heroku中的日志相同。任何帮助都会非常有用!感谢。
编辑:我想我只是使用django-debug-toolbar