Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

585
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!