我所试图做的是以下几点:Django的认证用户搜索工作不正常
1. Retrieve a User record (from the DJango authentication system) is in
the DB
2. get the Username (from that record)
3. Use the "username" to look for a record in a *different* table.
4. If the record *is not* there (in the *different* table), then create one.
我得到的是什么样子的查询到用户表,即使我已经中下面的错误views.py
from django.contrib.auth.models import User
而且,为什么DoesNotExist错误发生(当一个正在寻找在认证系统中的用户)目前尚不清楚。为什么我得到这个错误?
TIA
这是怎样的 “应用程序” 被构造
views.py
from django.shortcuts import render
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from authinduction.models import Mstrauthownerrdx
from django.contrib.auth.models import User
def inductowner(request):
username = request.POST.get('username')
user = User.objects.get(username=username)
myprofile = user.userprofileinfo
num_results = Mstrauthownerrdx.objects.filter(logonid=username).count()
if not (num_results == 0 or num_results == 1):
raise ValueError('Number of items found '+ num_results + ' is not valid')
if num_results == 0:
u = Mstrauthownerrdx.objects.create(logonid=username, emailaddr=user.email,
worktype=1, memo='OWNER', active=1, formpagelastfilled=myprofile.lastpgprocno,
formcomplete=myprofile.nextpgprocno, reclocktype=1, reclockid=1)
u.save()
return render(request, 'authinduction/owner/index.html')
感谢您的答复。我看到我没有获得价值回归的原因是因为这部分代码:“username = request.POST.get('username')”返回None。 –