from django.shortcuts import render
from .forms import *
from .models import *
from django.http import HttpResponsePermanentRedirect
from django.core.cache import cache
import datetime
def index(request):
form = AppForm(request.POST)
if request.method == 'POST' and form.is_valid():
new_form = form.save()
return HttpResponsePermanentRedirect("redirect")
IP_KEY = 'request_ban:{ip}'
DELAY = 3600
ip = request.META.get('HTTP_X_FORWARDED_FOR', '')
result = cache.get(IP_KEY.format(ip=ip))
if result:
difference = (result - datetime.datetime.now()).seconds
print(f'Вам осталось {difference} секунд')
else:
cache.set(
IP_KEY.format(ip=ip),
datetime.datetime.now() + datetime.timedelta(seconds=DELAY),
DELAY,
)
print('Добро пожаловать!')
return render(request, 'remontsite/footer.html', context={'form': form})
def redirect(request):
return render(request, 'remontsite/redirect.html')
все ламер разобрался :D