Monday, June 12, 2017

Re: Failed to load resource: the server responded with a status of 500 (INTERNAL SERVER ERROR)

On Monday 12 June 2017 11:18:52 Akhi wrote:

 

> def email_view(request, id):

> course = get_object_or_404(CourseWare, pk=id)

> user = UserProfile.objects.get(user__id=request.user.id)

> myorder = MyOrder.objects.get_or_create(buyer=user, course=course)

 

Return value for get_or_create() is tuple(obj: models.Model, created: bool).

So your if check is useless as it is always true. But your method signature is incorrect as well. You're not supplying defaults.

 

On top of that, you fetch the user profile twice and both cases can blow up if no profile exists.

--

Melvyn Sopacua

No comments:

Post a Comment