1👍
The whole piece of code is unnecessary. self.user
is already an instance of User. There’s absolutely no point getting that user’s username and using that to query the User model again: you’d just get back the exact same data you started with.
Just use self.user
directly.
0👍
do this
from django.views import generic
class GetUserData(generic.View):
def get(self, *args, **kwargs):
user = self.request.user
if user.username:
myuser = UserData.objects.filter(username=user.username)
if myuser:
print 'coo'
else:
print 'nope'
If the data is coming from Get request then do this:
get_data = self.request.GET # Parse get set after then blammo
- [Answer]-Django CreateView demands pk
- [Answer]-Django: how to customize my data in pivot chart of chartit module
- [Answer]-Django Sorting a List inside a model
- [Answer]-Is it possible to ignore a system check error in Django 1.7+
Source:stackexchange.com