Я не совсем уверен, что именно вы пытаетесь сделать, но вот минимальный рабочий пример (без JS или AJAX), который вы можете изменить, чтобы он соответствовал вашим потребностям.
Он использует принцип настройки повара ie с максимальным возрастом, эт c например здесь
Главное, что делает эту работу, - это настройка http-equiv="refresh"
метатег в html должен соответствовать тому же периоду времени, что и max_age
повара ie. Таким образом, страница будет автоматически ссылаться на sh сразу после истечения срока действия ie (который мы установили) и страница будет перенаправлена без дальнейшего ввода.
views.py
from django.shortcuts import redirect, render
def initial_page(request):
# Set the cookie
response = redirect("video-call")
# You probably want to set it only once for each user and make this secure
response.set_cookie(
"call_timeout",
"1",
max_age=3600 # Set this to the time you need
)
return response
def video_call_page(request):
# See if the cookie has expired
# (This will auto-check because of the http-equiv="refresh" in the HTML)
try:
c = request.COOKIES['call_timeout'] # Try to access the cookie
context = {}
# The cookie hasn't expired, so continue
return render(request, "vid_call.html", context)
except KeyError:
# The time is up, so redirect to the page of your choice
return redirect("expire_redirect")
def redirect_page(request):
# The cookie expired
context = {}
return render(request, "redirect.html", context)
urls.py
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls import url
from django.conf.urls.static import static
from .views import initial_page, video_call_page, redirect_page
urlpatterns = [
url(r'^$', initial_page, name='initial'),
url(r'^video-call/$', video_call_page, name='video-call'),
url(r'^expired/$', redirect_page, name='expire_redirect'),
path('admin/', admin.site.urls),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT
vid_call. html
{% load static %}
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<!-- Set http-equiv="refresh" to the same as the max_age param -->
<meta http-equiv="refresh" content="3600">
</head>
<body>
<h1>Video call page</h1>
<video width="320" height="240" autoplay>
<!-- Set the path to a test video in your static dir (represents your video call) -->
<source src="{% static 'mov_bbb.mp4' %}" type="video/mp4">
Your browser does not support the video tag.
</video>
</body>
</html>
перенаправление. html - это просто содержимое страницы, на которое вы хотите, чтобы пользователь был перенаправлен через час ( или любой другой период времени и т. д. c.), поэтому я не буду включать его здесь.
Спасибо.