Django On Production For Post Request Throws Server Error(500) On Compute Engine
I have deployed my Django 1.10 with python 3.6 Project on Google compute engine when I have changed Debug = True in my settings.py to Debug = False it throws Server Error (500) on
Solution 1:
As discussion above from comments, you can put exception handling in code and put logger
in the code. For example:
import logging
classTagView(LoginRequiredMixin, generic.CreateView):
form_class = forms.TagForm
defpost(self, request, *args, **kwargs):
try:
post_data = request.POST.copy()
post_data.update({'user': request.user.pk})
form = forms.TagForm(post_data)
if form.is_valid():
tag = form.save(commit=False)
tag.user = request.user
tag.email = request.user.email
tag.save()
else:
return HttpResponse(form.errors, status=400)
return HttpResponseRedirect(reverse_lazy('users:dashboard'))
except Exception as exp:
logging.error(exp) # For python 3return HttpResponse(exp, status=400)
And view the error logs using log monitoring tool like this blog mentioned: https://cloud.google.com/python/monitor-and-debug/logging-application-events
Details about exception handling: https://docs.python.org/3/tutorial/errors.html
*** As per discussion in the comments in the answer, the problem resides in ALLOWED_HOSTS
. Setting ALLOWED_HOSTS=['*']
or Setting the IP of the Server in Allowed Host solved the issue.
Post a Comment for "Django On Production For Post Request Throws Server Error(500) On Compute Engine"