Django:某些页面上的身份验证问题

时间:2019-04-21 20:41:54

标签: python django

在我的Django项目中,我创建了一个身份验证页面,但是其他一些页面要求我登录。

如果我使用另一个函数的代码,那没问题,那真的很奇怪。

使用登录名和密码登录页面即可。

我的主页:

{% extends "base.html" %} //include {% if user.is_authenticated %}

{% block body %}
  <a href="{% url 'list_users' %}">Display user list</a>//work
  <br>
  <a href="{% url 'create_user' %}">Add new user</a>//work
  <br>
  <a href="{% url 'test' %}">Test</a>//doesn't work ask me to login
  {% endblock %}

我的list_user页面:

def list_users(request):
    couch = couchdb.Server('http://foo:bar@localhost:5984/')
        x = []//useful information
    return render(request, 'blog/list_users.html', locals())

我的测试页,在那里我尝试新事物:

def test(request):
    couch = couchdb.Server('http://foo:bar@localhost:5984/')
    db = couch['_users']
    list_profile = []
    x = -1
    for id in db:
        if id != "_design/_auth":
            user = db[id]
            db_user = couch['userdb-' + user['name'].encode('utf-8').hex()]
            list_profile.append([])
            x = x + 1
            try:
                doc = db_user['profile']
                list_profile[x].append(id[17:])
                list_profile[x].append(doc['firstName'])
                list_profile[x].append(doc['lastName'])
                list_profile[x].append(doc['email'])
            except:
                list_profile[x].append(id[17:])
                list_profile[x].append("")
                list_profile[x].append("")
                list_profile[x].append("")
    return render(request, 'blog/test.html', locals())

最后一个功能要求我登录,而不是另一个。

如果我使用list_user的代码并将其放入功能测试中,一切正常。

我该如何解决这个问题?

0 个答案:

没有答案