在我的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 %}
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
的代码并将其放入功能测试中,一切正常。
我该如何解决这个问题?