I'm deploying a Django App live for the first time, and everything has gone relatively smoothly so far. My site works fine, except for one CreateView (EstRequestCreateView) that works locally, but when I try to create new Estimate Request in Production I receive a Bad Request (500) response. I've added some print statements to the code just to identify where it's failing, but it appears to be behind the scenes somewhere as it makes it all the way through both of my functions no problem.
Here is my View:
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)
And here is my log in 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
The only thing that is somewhat helpful coming from Heroku is the response 500. I've added the Print statements to make sure the functions I have defined are running at least up to the Return statements. I'm not sure what is wrong and I'm not sure how to debug this further. Like I said it's working perfectly in Test.
Can someone help me point out what I might be wrong? Or if not help me understand how I can debug production with more success. I tried adding the papertrail logging plugin to my Heroku app, but it appears to be the same log I have in Heroku. Any help would be greatly apprecaited! Thanks.
Edit: I guess I'll just use django-debug-toolbar