Django HttpRequest.user attribute

in my my middleware is

MIDDLEWARE_CLASSES = [ "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.auth.middleware.SessionAuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", ]

and in my registered model I have the imports

from django.http import HttpRequest from django.contrib.auth.models import User

My question is why my request does not show a user attribute?

I am running the production server and when I save with the above the server stops with an AttributeError: type object 'HttpRequest' has no attribute 'user' cause I call HttpRequest.user

( In this answer: nothing additional is required and the Django docs were not helpful )

Category:django models Views:0 Time:2019-01-10

Related post

  • django embedding user id into URL template best practice 2009-11-26

    I'm building a navigation menu in my django app, and one of the options is "My Account". There are different roles I have for users, but in order for them all to view their profile, I use a generic URL such as http://mysite/user//profile. What's a Dj

  • PicklingError: Can't pickle suds.sudsobject.User: attribute lookup suds.sudsobject.User failed 2010-06-18

    I have a django application... I am accessing the web service using the SOAP suds client... I need to create a user object from the entries entered in the GUI... This user object is to be passed to a method... But i get the following error: PicklingE

  • Use an existing KerberosTicket to Bind to Ldap and search for users attributes 2009-03-26

    Is there a way in Java to query Active Directory for a users attributes given an existing that was forwarded to my code? I know I want to use Ldap to do the search but I am confused on how to use this Kerbe

  • How could I create a screen that would batch create a bunch of Django auth users? 2009-11-03

    I want to create a helper screen that can create a bunch of Django auth users on my site and have those accounts setup the same exact way as if they were done one by one through the Django auth GUI signup. What methods from Django auth would I have t

  • Django: Save User ID with Model Save 2010-02-08

    My question is very similar to this question: Unfortunately I did not quite understand their answer. When a user logs in I want them to be able to submit a link and

  • When do Symfony's user attributes get written to session? 2010-06-16

    I have a Symfony app that populates the "widgets" of a portal application and I'm noticing something (that seems) odd. The portal app has iframes that make calls to the Symfony app. On each of those calls, a random user key is passed on the query str

  • What are the default URLs for Django's User Authentication system? 2011-02-09

    Django's User Authentication system ( ) is incredibly helpful in working with users. However, the documentation talks about password reset forms and makes it seem like it takes care of it the same way

  • Django auth.user with unique email 2011-04-24

    I use the django.auth system and I've this: class RegisterForm(UserCreationForm): username = forms.RegexField(label= "Username" , max_length = 30, regex = r'^[\w]+$', error_messages = {'invalid': "This value may contain only letters, numbers and _ ch

  • How to filter admin options by a user attribute? 2011-05-03

    I have a model with a foreing key to a model called Country. Each time I edit my model in the admin, when diplaying the country option I see a lot of contries. I'd like that option list to be pre filtered by a user attribute (user.get_profile().conti

  • Rails 3: updating user attributes when authentications are created 2011-06-25

    I followed Railscasts #235 and #236 to setup creating user authentications with omniauth. I have a 2 boolean attributes on the user model called :fa

  • active record query returns hash of user_ids, find user attributes for each 2011-07-16

    User has many Relationships In my relationships table i have a field :referee containing a user_id for each record. Each record also has user_id foreign key I want to find the records that have in the :referee field and select user_id

  • Adding more validation to django admin user add forms 2011-07-18

    If we need to add more validation in django admin user add form like making the first name and last name and email compulsory.. Whats the way of achieving this?? --------------Solutions------------- You must create your own user form and adding your

  • How do i update a user attribute after signing in and signing out with devise gem 2011-07-18

    I am starting to use devise and i want to be able to update a user attribute to online or off line. i have this class ApplicationController < ActionController::Base private def after_sign_in_path_for(resource_or_scope) #update user status to onlin

  • Updating `User` attributes without requiring password 2011-08-16

    Right now, users can edit some their attributes without having to enter their password because my validations are set up like this: validates :password, :presence =>true, :confirmation => true, :length => { :within => 6..40 }, :on => :

  • Retrieving user attributes from Active Directory using LDAP - JAVA 2012-01-31

    EDIT: I've posted the solution below. I know you don't like these type of questions, but i've been struggling with this issue for half a day now. I've written a C# code that fetches user attributes from our Active Directory using LDAP, the code works

  • Django remote user authentication and security 2012-03-01

    I am using Django remote user authentication in a project. What I am actually using is just django.contrib.auth.RemoteUserBackend without the middleware, and manually calling authenticate after having checked with the backend that the user is legitim

  • How to turn a tornado HTTPRequest into a Django HttpRequest or WSGIRequest? 2012-03-08

    I'm writing a app using Django and TornadIO2/Tornado. In the TonradIO2 Session, I have access to Tornado's HTTPRequest objects. However, I have no access to a django request object in my event handlers in the SocketConnection class. Ideally

  • Extending Django's comments framework with Django's users and custom user profile 2012-03-25

    I'm running Django v1.4. I looked at the source code for django.contrib.django.comments and noticed that the Comment class has an optional user field that is a foreign key to Django's User. I have also extended User with my own UserProfile which has

  • How to retrieve user attributes through SAML in WSO2 Identity Server 2012-04-26

    I'm doing a sample webapp that authenticates against WSO2 Identity Server through SAML. It works fine but now I wanted to retrieve user attributes and roles for authorization and I'm completely lost. Reading some SAML docs I know that I must send an

  • Spring Security. How get LDAP user attributes? 2013-05-20

    Authentication is working correctly. I try to get LDAP user attributes using "search" metod of LdapTemplate. My spring-security.xml: <beans:beans xmlns="" xmlns:beans="

  • Django-AttributeError 'User' object has no attribute 'backend' (But-it does?) 2011-05-17

    In order to sign users in after registering them, I manually set the user.backend property. It normally works in my views. In this instance, I'm trying to register the user via AJAX. It is raising an AttributeError. Here is my code: def register_asyn

  • Django - AttributeError - 'User' object has no attribute 'validate' 2009-10-15

    I'm getting an AttributeError using rcrowley's django-twitterauth: Looks like it occurs when the validate() method is called on the user object, which the user object does not have. I don't know why the a

  • Some user attributes not showing up in django admin 2011-02-09

    In my custom authentication backend I extract the username, email, first and last name from an LDAP response and try to stick them into a newly generated User object if the user doesn't yet exist: user = User(username=username, email=result[0][1].get

  • Django: Populate user ID when saving a model 2009-05-14

    I have a model with a created_by field that is linked to the standard Django User model. I need to automatically populate this with the ID of the current User when the model is saved. I can't do this at the Admin layer, as most parts of the site will

  • Django-Admin: list_filter attribute from UserProfile 2010-02-12

    I want to allow the admins of my site to filter users from a specific country on the Admin Site. So the natural thing to do would be something like this: class UserAdmin(django.contrib.auth.admin.UserAdmin): list_filter=('userprofile__count

Copyright (C), All Rights Reserved.

processed in 0.097 (s). 11 q(s)