Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

224
Visualizações
Can't get JSON data on console

Trying to console.log the data before rendering it on page but I keep getting 404 not found or not attributeName 'Porfile' don't have username as an attribute.

I'm a noob when it comes to JSON, I've only started messing around with it recently, please help it's for an assignment

JS:

$.ajax({
    type: 'GET',
    url: 'my-profile-json/',
    success: function(response){
        console.log(response);
    },
    error: function(error){
        console.log(error);
    }
});

Urls:


from django.urls import path
from django.conf import settings
from django.conf.urls.static import static

from . import views
from .views import (
    post_view_json,
    profile_test_view,

    MyProfileView,
    MyProfileData,
)


urlpatterns = [
    path("", views.index, name="index"),
    path("login", views.login_view, name="login"),
    path("logout", views.logout_view, name="logout"),
    path("register", views.register, name="register"),
    path("test", profile_test_view, name="test"),
    path("my/", MyProfileView.as_view(), name="my-profile-view"),
    path("my-profile-json/", MyProfileData.as_view(), name="my-profile-json"),

    # endpoints
    path("posts-json/", post_view_json, name="posts-view-json")
]

Views

from django.contrib.auth import authenticate, login, logout
from django.db import IntegrityError
from django.http import HttpResponse, HttpResponseRedirect
from django.http.response import JsonResponse
from django.shortcuts import render
from django.urls import reverse
from django.core import serializers

from .models import User, Post, Profile
from django.views.generic import TemplateView, View


class MyProfileData(View):
    def get(self, *args, **kwargs):
        profile = Profile.objects.get(user=self.request.user)
        qs = profile.get_proposals_for_following()
        profiles_to_follow_list = []
        for user in qs:
            p = Profile.objects.get(user__username=user.username)
            profile_item = {
                'id': p.id,
                'user': p.username,
                'avatar': p.avatar.url,
            }
            profiles_to_follow_list.append(profile_item)
        return JsonResponse({'pf_data': profiles_to_follow_list})

class MyProfileView(TemplateView):
    template_name = 'network/my_profile.html'
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here you use p.username but it should most certainly be p.user.username:

profile_item = {
                'id': p.id,
                'user': p.username,
                'avatar': p.avatar.url,
            }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda