Friday, November 13, 2020

Re: im a newbe, i'm trying to get the username in a view

make an attribute named "user"

On Fri, Nov 13, 2020 at 2:27 PM Apolo Machine <apolomachine@gmail.com> wrote:
I'm trying to get the username within a view(CBV), the documentation I found says that the logged user is within the request, but when I do

class ServiceCreateView(LoginRequiredMixin, CreateView):
          model = Service
          form_class = ServiceForm
          user=request.user.username

i get this error

AttributeError: module 'django.http.request' has no attribute 'user

any help is appreciated

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8635848c-b7fc-4b6b-9b53-f6107ce42717n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAcuwDfBL82t2WebGvYmUEiP%2BCD7tv3aBTL7f%2BrH0igzVUbSuQ%40mail.gmail.com.

No comments:

Post a Comment