我想要一种方法来检查是否有人用django填写了他们的个人资料信息(新用户)。如果他们不想展示一种在所有信息填写完毕之前都不会消失的模式。无论他们进入哪个页面,它都应该显示此模式直到填写完毕。确定新网站用户的最佳方法 - Django
我应该使用javascript(ajax)来检查一个路线,该路线将使检查并返回一个带有答案的json请求?如果json对象说他们是新的,我会动态地将模态附加到屏幕上。
更新:我使用django的身份验证系统。这里是一个登录的例子。该检查将是类似的,但我将使用另一个扩展了Django基本用户类的应用程序中创建的模型。我称之为user_profile。我可能会检查是否设置了用户的名字。如果不是,我会想执行检查。
def auth_login(request):
if request.POST:
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user:
# the password verified for the user
if user.is_active:
print("User is valid, active and authenticated")
request.session['id'] = user.id
request.session['email'] = user.email
login(request, user)
data = {}
data['status'] = "login"
return HttpResponse(json.dumps(data), content_type="application/json")
#redirect
else:
print("The password is valid, but the account has been disabled!")
else:
# the authentication system was unable to verify the username and password
print("The username and password were incorrect.")
data = {}
data['status'] = "The username and password are incorrect"
return HttpResponse(json.dumps(data), content_type="application/json")
return HttpResponse("hello")
有这样做的许多方面。你可以提供更多的上下文来缩小答案的范围。你有一个认证系统,即你可以检查'request.user.is_authenticated()'吗? – YPCrumble
也许提供你的视图代码,因为这是最有可能发生这种检查的地方。 – YPCrumble
@YPCrumble我用一个例子更新了这个问题。是的,我使用Django的身份验证系统。 –