如何保持用户登录Django

我在应用程序中登录了。然后,我转到列出数据库中所有用户的屏幕。当我选择一个指定的用户时,我丢失了登录的用户。那么,如何使我的用户保留在所有应用程序中?


我的views.py列出了所有用户。这一次,该网址显示了我的用户(http:// localhost:8000 / os / acesso / consultausuario / 9)


def acesso_consultausuario(request, id=None):


    instance = get_object_or_404(usuario, id=id)


    queryset = usuario.objects.all().order_by('dat_criacao_usuario')

    instancia_usuario_filter = usuariofilter(request.GET, queryset=queryset)


    table = usuariotable(instancia_usuario_filter.qs)


    RequestConfig(request, paginate={'per_page': 25}).configure(table)


    paginator = Paginator(instancia_usuario_filter.qs, 5)

    page = request.GET.get('page')


    try:

        response = paginator.page(page)

    except PageNotAnInteger:

        # if page is not an integer, deliver first page

        response = paginator.page(1)

    except EmptyPage:

        # if page is out of range, deliver last pages of results

        response = paginator.page(paginator.num_pages)


     context = {

        "instance": instance,

        "filter": instancia_usuario_filter,

        "response": response,

        "table": table,

    }

    return render(request, 'consulta/consulta_usuario.html', context)



# Show an especified user that I selected before.

def acesso_consultausuariodetalhe(request, id=None):


    # Instância do usuário que foi selecionado na consulta

    instance = get_object_or_404(usuario, id=id)


    form = statususuarioForm(request.POST or None)


    if form.is_valid():  # All validation rules pass


        instance_status = form.save(commit=False)

        var_status = form.cleaned_data['statususuario']

        instance_status = statususuario.objects.get(desc_statususuario=var_status)



守着一只汪
浏览 105回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python