-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'NoneType' object has no attribute 'name' #8
Comments
same problem..please anybody provide the solution for this? |
same problem |
This error is coming because User.objects.get(username=request.user.username).cluster_set.first() is returning null..
|
This problem occurs when you create a new user, but they do not belong to any cluster and could not get any recommendation. In the if num_reviews % update_step == 0: means that the cluster only updates when the num_reviews is some magic number, i.e. not every time. But we need to update the cluster every time when a new user is registered so that they can get recommendations based on their cluster. I fix this issuer by changing the update_clusters() function to take a boolean "is_new_user" as argument, like this: def update_clusters(is_new_user):
num_reviews = Review.objects.count()
update_step = 10
# Recluster users when every <update_step> reviews are added or when a new user is created
if num_reviews % update_step == 0 or is_new_user:
... Then, in the @login_required
def recommendation(request):
...
try:
user_cluster_name = User.objects.get(
username=request.user.username).cluster_set.first().name
except:
# If this user does not belong to any cluster, update the clusters.
update_clusters(is_new_user=True)
user_cluster_name = User.objects.get(
username=request.user.username).cluster_set.first().name While in the add_review view: def add_review(request):
...
update_clusters(is_new_user=False)
... This way, it guarantees that when a freshly registered hit the recommendation page, the cluster will update and they will be put into some new cluster, but when users are adding reviews, the cluster only updates every 10 new reviews are added. |
I tried this but I am getting this error- raise TypeError('Expected rank <=2 dense array or matrix.') |
@venkat527 I'm not sure why you get that error. I suspect it has something to do with the matrix manipulation with the |
Everything is working at stage, except i get an error on recommendation page.
Line causing the error :
user_cluster_name =
User.objects.get(username=request.user.username).cluster_set.first().name
'NoneType' object has no attribute 'name'
Request Method: GET
Request URL: http://192.168.99.100:8000/reviews/recommendation/
Django Version: 1.11
Exception Type: AttributeError
Exception Value:
'NoneType' object has no attribute 'name'
Exception Location: /code/reviews/views.py in user_recommendation_list, line 92
Python Executable: /opt/conda/bin/python
Python Version: 3.6.0
The text was updated successfully, but these errors were encountered: