I have my Django application deployed in Heroku at free dyno
.
I am currently sending some requests GET
and POST
from JQuery / ajax
In my local development environment, the requests to my url endpoints work very well, as seen in this example on my local Django Server:
In my production / testing environment of Heroku, something strange happened. With a first user I proceeded to perform the GET and POST test and they work perfectly.
But when I do the same with another user of my application deployed in Heroku, whether the request is GET or POST throws the error of 500 Internal Server Error
I do not know the reason why in Heroku, I am accepted by ajax requests for one user and not for another.
Would this be related to the fact that I am using a free dyno
?
I checked in my Heroku logs according to this answer and for GET requests this log comes out:
2017-09-01T12:34:31.053127+00:00 heroku[router]: at=info method=GET path="/api/post/?q=" host=hostayni.herokuapp.com request_id=acd319f7-d47d-4e6c-833f-a0ef34163c51 fwd="190.240.77.93" dyno=web.1 connect=1ms service=615ms status=500 bytes=253 protocol=http
And for POST requests this is the log:
2017-09-01T12:37:56.512868+00:00 heroku[router]: at=info method=POST path="/api/post/create/" host=hostayni.herokuapp.com request_id=6d51cd89-431e-4b6e-80fe-55a505433fcc fwd="190.240.77.93" dyno=web.1 connect=1ms service=150ms status=500 bytes=253 protocol=http
Both reference me the status=500
that I see in my browser console, but there is no more detail in relation to what I can do or how to proceed about it.
Would this have to do with the fact that I am using a free Heroku server and not a payment server?
I'm intrigued by the possibility that Heroku has picked up the requests ( GET
and POST
) of my first user and allowed them (the times that are) and then others not, such as mouths or just to indicate that if I want to everyone else, I must switch to a paid plan or professional dyno
Error 500 is certainly something on the server side, but I do not currently have elements to know what happens ...
What recommendation or suggestion can you give me? Is it possible that this would happen better to another server like Amazon EC2 to avoid these problems (I would still have to pay and it is fine if I have to do it) or is this independent and should I see how to attack the problem on my server?
If it's error 500
, can it possibly be gunicorn?
The version I use in production is gunicorn==19.7.1
UPDATE
This is the code of my view that inherits from ListAPIView
which generates an endpoint / api / post / which is where the request GET
from ajax is sent to recover the posts of a user.
In this view I handle two scenarios
A. I capture the request of a user to be able to see their own posts made
B. I request a list of the users that I am following and I retrieve your posts.
class PostListAPIView(generics.ListAPIView):
serializer_class = PostModelSerializer
pagination_class = StandardResultsPagination
def get_queryset(self, *args, **kwargs):
# Capturamos el request de un usuario
requested_user = self.kwargs.get("email")
if requested_user:
# Para ver los posts mios y los que reposteo
qs = Post.objects.filter(user__email=requested_user).order_by('-timestamp')
query = self.request.GET.get("q", None)
if query is not None:
# Para buscar por usuario y por su contenido
qs = qs.filter(
Q(content__icontains=query) |
Q(user__email__icontains=query)
)
return qs
else:
im_following = self.request.user.profile.get_following()
# Mostrando los posts de los usuarios que sigo
# Bind querysets
# Para ver los posts de los que sigo y los mios
qs1 = Post.objects.filter(user__in=im_following)
qs2 = Post.objects.filter(user = self.request.user)
qs = (qs1 | qs2).distinct().order_by('-timestamp')
# print(self.request.GET)
query = self.request.GET.get("q", None)
if query is not None:
qs = qs.filter(
Q(content__icontains=query) |
Q(user__email__icontains=query)
)
return qs
This view PostListAPIView
is reached in the following way
I define this url in% main% co
url(r'^api/post/', include('posts.api.urls', namespace='post-api')
And in the urls.py
of my application of urls.py
:
url(r'^$', PostListAPIView.as_view(), name='list'),
From my html template with JQuery, I do a posts/api/urls.py
of the url / api / post in the following way:
{% extends "layout.html" %}
{% block script %}
// Codigo basico para traernos datos de REST
<script>
$(document).ready(function(){
console.log("working");
$.ajax({
url: "/api/post/",
method: "GET",
success: function (data) {
console.log("the data are")
console.log(data)
},
error: function(data){
console.log("error")
console.log(data)
}
})
});
</script>
{% endblock script %}
I appreciate the support with this topic:)