how to reload page in django using js2py?

Viewed 34

i run script every 15 mins to update data on my website but i want to reload ppage in browser after update automatically

i tried to put window.location.reload(true) using js2py and script looks like this:

import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')

import django
django.setup()

from django.core.management import call_command
import time

import js2py

js = """
window.location.reload(true);
"""

def reload():
    context = js2py.EvalJs()
    context.execute(js)


while True:
    call_command("feed_update")
    reload()
    time.sleep(900)

and i get error:

raise MakeError('TypeError',                                                                                        
js2py.internals.simplex.JsException: TypeError: 
Undefined and null dont have properties (tried getting property 'reload')    
1 Answers

You don't need this library

def reload():
    return HttpResponse("<script>window.location.reload(true);</script>")

or

def reload():
    return HttpResponse(
        "window.location.reload(true);",
        content_type="application/x-javascript"
        )
Related