views.py
Код: Выделить всё
def Tweets_view(request, *arg, **kwargs):
qs = Tweets.objects.all()
for x in qs:
tweet_list = { 'id': x.id, 'content': x.content }
context = { 'response': tweet_list }
return JsonResponse(context)
Код: Выделить всё
from django.contrib import admin
from django.urls import path
from tweets.views import Tweets_view_id, Tweets_view
urlpatterns = [
path('admin/', admin.site.urls),
path('tweets', Tweets_view), #N.B This is the URL I'm trying to access.
path('tweets/', Tweets_view_id)
]
Код: Выделить всё
{% extends './base.html' %}
{% block content% }
LOADING ...
const tweetsElement = document.getElementById("tweets")
const xhr = new XMLHttpRequest()
const method = "post"
const url = "/tweets"
const responseType = "json"
xhr.responseType = responseType
xhr.open(method, url)
xhr.onload = function () {
const serverResponse = xhr.response
var listedItems = serverResponse.response
console.log(listedItems)
}
xhr.send()
{% endblock content% }
Это ссылка на изображение отображения моего браузера. В моей консоли нет данных.
Подробнее здесь: https://stackoverflow.com/questions/630 ... e-response