I have my Django application deployed on Heroku in a free dyno Currently, I am sending some GET and POST requests from JQuery-1.12.4 version
In my local development version of my application, the requests to my REST endpoints services it’s works Here an example of the fetch of posts of an user, consuming from ajax to endpoint rest service
This is my localhost Django server
I deploy on Heroku free dyno this same user interface, but the behavior is the following:
The server throw an error 500, although was happen some inusual or strange Previously, when I create an user for first time in my Heroku deployment to this user, the create and fetch post functionality it’s works O.K. like in my local environment development.
Heroku accept GET and POST request from JQuery AJAX ONLY to this user, such as follow in this picture:
I Unknown the reason which Heroku like production/testing server deployment does not accept or accept limited AJAX requests. Is possible (I think so, and will be too logic) that this behavior to be due to I am using free dyno heroku server?
Why only accept ajax request to just an user and other users like the images show above, does not works the ajax requests?
In this question talk about the topic, but I don’t have clear this subject
What other option suggest to me in relation to deployment of my project?
AWS EC2? may be?
The Heroku free dyno, don't let me look the logs due to in this free dyno, does not saved files ..
I appreciate some orientation about it.
Best Regards
UPDATE
I can look the logs in my heroku deployment, according to this answer
By the moment, the logs in the GET and POST operation only tell me about of status 500
This is the logs when I perform the GET request
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 this is the log when I perform the POST request
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
In this moment I don't know how to proceed in relation to status=500
from my JQuery ajax requests
This is the code of my view which inherit of ListAPIView. Here I am creating an endpoint /api/post/
in where the ajax GET
request is sent to retrieve the user posts
In this view I manage two scenaries:
a. I get the request of user to view their posts b. I request a list of users which I am following and retrieve their 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
From my html template, I perform the ajax GET request of this 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 highly some orientation about it.