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_class = ServiceForm
> user=request.user.username
>
> i get this error
>
> AttributeError: module 'django.http.request' has no attribute 'user
>
The documentation for the user attribute here:
https://docs.djangoproject.com/en/3.1/ref/request-response/#attributes-set-by-middleware
says "Some of the middleware included in Django's contrib apps set
attributes on the request. If you don't see the attribute on a request,
be sure the appropriate middleware class is listed in MIDDLEWARE."
So maybe you should check your MIDDLEWARE settings?
Kind regards,
Kasper Laudrup
--
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/d3ee16bf-eb6e-2c8b-a3f6-efc7237296d3%40stacktrace.dk.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment