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

588
Visualizações
How to connect Django Rest API to a html CSS JS frontend

I am new to programming and one thing I am very confused about, my boss has told me to create a rest API about an app which I have completed all the signups, login, and other parts. But now I have to create a frontend but all the tutorials on the internet are about create rest API of Django to react or some other frontend framework, is their any tutorial on YouTube about connecting to a html CSS JavaScript on frontend to Rest API. thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you don't want a frontend just follow the official django tutorial to learn how to serve html/css/js from django.

From there you can either pass the data you need from your api down through the django context, or you can use fetch or something similar to grab it from javascript.

The latter would look like this.

# views.py
def index(request):
    return render(request, 'index.html')

def apiview(request):
    return JsonResponse({'title', 'served from api'})

index.html
<div class="title" token={{csrf_token}}></div>
<script>
function getTitle() {
    const div = document.querySelector('title')
    const csrf_token = div.getAttribute('token')
    fetch('localhost:8000/apiview', {
        method: 'get',
        headers: {'X-CSRFToken': token}
    })
    .then(data => data.json())
    .then(data => div.innerHTML = data.title)
}
</script>
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