Reputation: 1414
I am trying to pass some information to a view in Django in order to filter a list and then pass this back to the user. In order to do so I have the following in my urls.py:
url(r'^info/user/(?P<user_id>\d+)$', views.UserInfoView, name='active_reservations'),
and the following view defined:
def UserInfoView(request, **kwargs):
template = "parking/detail_user.html"
user = User.objects.filter(user=self.kwargs['user_id'])
context = {"user": user}
return render(request, template, context)
However, each time I try this I get the error: NameError at /info/user/1 global name 'self' is not defined
Any ideas?
Upvotes: 0
Views: 69
Reputation: 1435
You should change the view function. Replace **kwargs with user_id
def UserInfoView(request, user_id):
template = "parking/detail_user.html"
user = User.objects.filter(user=user_id)
context = {"user": user}
return render(request, template, context)
Upvotes: 1
Reputation: 31532
kwargs is not an attribute of self. Your code should be:
user = User.objects.filter(user=kwargs['user_id'])
Upvotes: 1