Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9256695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:00:34+00:00 2026-06-18T12:00:34+00:00

Imagine a simple page with a counter and two buttons. The value displayed by

  • 0

Imagine a simple page with a counter and two buttons. The value displayed by the counter is a read/stored in a model’s field. I want that when I press the “green” button the counter is incremented by one and when I press the “red” button the counter is decreased by one. What’s the best way to implement such behavior:

  1. Button calls model’s method (Django method) which updates the model’s field (DB write); Entire page is refreshed and the counter display updated (DB read).
  2. Button calls javascript function which updates the counter display (JS/HTML); In the background, a model’s method (Django method) is called to update the model’s field (DB write).
  3. Yet another way?

Can the javascript code call a Django function? I’m a newbie at Django (I followed the tutorial up to part 4). I already understood the MVC/MTV concept and the data read/write/display, but what’s bothering me now is introducing behavior/interactivity on my pages.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:00:36+00:00Added an answer on June 18, 2026 at 12:00 pm

    JavaScript in browser-side is sitting on the front end, while Django is serving on the backend(server-side). The former can neither nor need to directly call the latter’s functions. The interface between them is typically web service APIs, namely, browser that makes AJAX calls with URLs defined in web services, which are backed by Django.

    More specifically, JavaScript sends HTTP requests to web server, in turn Django’s URL dispatcher maps the request URLs to corresponding Django views(function-based or class-based). In short, a typical route can be simplified as:

    JavaScript -> HTTP request -> Django URL dispacher(mapping rules are in urls.py or urls/XXX.py) -> Django view function(views.py or views/XXX.py) -> Django form(optional) -> Django model(optional).

    For more Django technical details, you may refer to Django tutorial or Practical django Projects.

    Final word: even if JavaScript could call Django function method/function, it should be avoided. From web service’s perspective, Django methods/functions are only implementation detail, which are more subject to change(compared to web service API). Backend developers may change function name, switch to some framework other than Django, or even change programming language like Java, Ruby or PHP for whatever reason.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let us have some simple page that allows logged users to edit articles. Imagine
I think this is a simple question. Imagine you have a page that initializes
Imagine a simple page with a list of users. Selecting a user displays a
Imagine two simple java applications. Both of them are implementing the same JAR file
Imagine a simple html page with 3 iframes pointing to the same url: <html
I am creating a simple web page that will allow the user to select
Making a simple three question PHP quiz. Each question is displayed on a page
I want to close the window after loadFinished complete. imagine simple code: class Example(QWebView):
imagine you have simple page like this: Hi everybody. when you click here new
Let's imagine the following situation: You have a simple php page with an html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.