0

HI!

I want to make a page specifically Django that when you click on the button starts to throw numbers with an interval of 1 second and stop with other button, but without reloading the page, only the section of html.

I've been looking and I need to use ajax, but I do not understand many concepts of this technique, I begin to feel frustrated.

This is my overall idea.

base.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Example</title>
</head>
<body>

    <h1 >Number of PI</h1>

    <!--Data-->
    <div style="border-style:solid; border-width:1px;">
        {{pi}}
    </div>

    <br>
    <!--Buttons-->
    <button>Start</button>
    <button>Stop</button>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script>
</body>
</html>

views.py

from django.shortcuts import render

import random

# Create your views here.
def base(request):
    context={"pi":str(random.random())}
    return render(request,"app/base.html",context)

This example works but I have to refresh the page THANKS!

6
  • where is your ajax request ? Commented Dec 28, 2015 at 19:15
  • I never used ajax, I've been looking for some examples, but I do not understand some parts, you could guide me with a basic example? thanks Commented Dec 28, 2015 at 19:18
  • 1
    This should get you started: stackoverflow.com/questions/3776571/… Edit the question with your code if you find yourself stuck Commented Dec 28, 2015 at 19:21
  • thanks for example, in the line "url: '{% url%} monitor-test'," monitor-test is the name of the html view? which means that line?, thanks again Commented Dec 28, 2015 at 19:28
  • Yes. You need to make a few more changes (specific to your view) Commented Dec 28, 2015 at 20:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.