Django 保存获取请求的历史记录

Django save history of get request

我正在开发一个 django 应用程序,人们可以在其中输入他们的 ID,然后他们要么获得活跃客户,要么不获得。

已经解决了,我想要的是在每次有人尝试输入他们的 ID 时保存

这是观点:

def ingreso_cliente(request):
query_string = ''
found_entries = None
activo = None
#sin buscar
retorno = '3'
today=datetime.now

if ('idcliente' in request.GET) and request.GET['idcliente'].strip():
    #filtro por el usuario
    query_string = request.GET['idcliente']
    entry_query = get_query(query_string, ['cliente__ci'])
    #filtro por el mes
    found_entries = Pagos.objects.filter(entry_query).order_by('cliente__ci')

    activo = found_entries.filter(Q(mes_desde__lte=today)&Q(mes_hasta__gte=today))
    if (not activo):
        #deudor
        retorno = '2'
    else:
        #activo
        retorno = '1'



return render_to_response('ingreso_cliente.html', { 'retorno':retorno, 'today':today }, context_instance=RequestContext(request))

这是我用来输入客户 ID 的模板,如果他处于活动状态,我会得到:

<form method="get" action="/home/ingreso_cliente/">
<input type="text" name="idcliente" id="idcliente"/>
<input type="submit" value="Buscar"/>
</form>

hora: {{today}}

{% if retorno == '1' %}
    <span>Cliente Activo</span>
{% elif retorno == '2'%}
    <span>Cliente Deudor</span>
{% endif %} 

它是一个获取请求,要保存在数据库中,我需要一个 POST,但是对于 POST,我无法从数据库中获取数据以了解其是否处于活动状态。有什么办法吗?

通过 GET 或 POST 提交表单没有区别。

在您的视图结束时(return 之前不久),执行如下操作:

LoginAttempt.objects.create(username=query_string, active=retorno)

其中 LoginAttempt 是保存登录尝试的模型。这并不理想,但您明白了,可以使用 logging 界面或任何您想要记录尝试的方式。

PS。您的表单也可以与 POST 完美配合,但显然您需要在 request.POST 而不是 request.GET

中查找 idcliente