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

2020-11-15 Thread Bunh Tha Chau
initial = super(ServiceCreateView, self).get_initial() initial = initial.copy() initial['user'] = self.request.user.username return initial  Vào lúc 19:24:50 UTC+7 ngày Chủ Nhật, 15 tháng 11, 2020, apolom...@gmail.com đã viết: > Thanks to all of you. > I finall

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

2020-11-15 Thread Apolo Machine
Thanks to all of you. I finally get it work with this def get_initial(self): initial = super(ServiceCreateView, self).get_initial() initial = initial.copy() initial['user'] = self.request.user.username return initial El sáb., 14 nov. 2020 a las 19:59, David Nugent (

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

2020-11-14 Thread David Nugent
The pre-requisite for having ‘user’ in the request instance is the ‘django.contrib.auth.context_processors.auth’ in your TEMPLATES context_processors. See the second answer (should be the accepted one as it has received far more community votes) in this stack overflow article

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

2020-11-14 Thread mike vickers
You would want to include that line in a method, not as a class attribute. For example: def get(self, request): user = request.user.username ... return render(... On Sat, Nov 14, 2020 at 9:37 AM Kasper Laudrup wrote: > Hi Barbara, > > On 13/11/2020 22.46, Barbara Leonar

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

2020-11-14 Thread Kasper Laudrup
Hi Barbara, On 13/11/2020 22.46, Barbara Leonard wrote: make an attribute named "user" How would that help? The attribute value should be set to the currently logged in user. Just adding the attribute to request object will not do that. Clearly something else is missing. Kind regards, Ka

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

2020-11-14 Thread Kasper Laudrup
Hi Apolo, On 13/11/2020 19.19, Apolo Machine 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_cl

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

2020-11-13 Thread Barbara Leonard
Yes I believe so I did programming years ago but from the error code you are getting I would say try that because the syntex can not process what it does not have. It is telling you it do not have an attribute named user there it can not return such output, so yes try the module area to put in the

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

2020-11-13 Thread Apolo Machine
where? in my model service? i'm not quiet understand thanks for responding El vie., 13 nov. 2020 a las 18:53, Barbara Leonard (< barbaraleona...@gmail.com>) escribió: > make an attribute named "user" > > On Fri, Nov 13, 2020 at 2:27 PM Apolo Machine > wrote: > >> I'm trying to get the username w

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

2020-11-13 Thread Barbara Leonard
make an attribute named "user" On Fri, Nov 13, 2020 at 2:27 PM Apolo Machine 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): >

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

2020-11-13 Thread Apolo Machine
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