I'm new to django and trying to get my machine learning model to display recommendations for a logged in user.
The current view is this:
def my_view(request):
username = None
if request.User.is_authenticated():
username = request.User.username
result3 = get_recommendation(username, n=10)
return render(request,'test.html', {'result3':result3})
else:
pass
It searches for the currently logged in user, and passes their user id (their username) into the function to get a recommendation for that user, and attempts to impute the result onto a html test page (the user is already logged in to be accessing this test page). The test page itself looks like this:
{% if user.is_authenticated %}
{{ result3 }}
{% endif %}
Does anyone know what I'm doing wrong?
Your html should be like this instead:
{% if request.user.is_authenticated %}
{{ result3 }}
{% endif %}
And your views.py
def my_view(request):
username = None
if request.user.is_authenticated():
username = request.user.username
result3 = get_recommendation(username, n=10)
return render(request,'test.html', {'result3':result3})
else:
pass
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.