django-users

How to delete user in django?

一曲冷凌霜 提交于 2019-12-08 03:33:00
问题 This may sounds a stupid question but I have difficulty deleting users in django using this view: @staff_member_required def del_user(request, username): try: u = User.objects.get(username = username) u.delete() messages.sucess(request, "The user is deleted") except: messages.error(request, "The user not found") return render(request, 'front.html') in urls.py I have url(r'^del_user/(?P<username>[\w|\W.-]+)/$', 'profile.views.del_user'), Instead the user being deleted I get The user not found

Django user.is_authenticated works some places, not others

有些话、适合烂在心里 提交于 2019-12-07 08:06:09
问题 In my template, I have the following: <ul class="tabbed" id="network-tabs"> {% if user.is_authenticated %} <li><a href="{% url acct-my-profile %}">My Account</a></li> <li><a href="{% url acct-logout %}">Log Out</a></li> {% else %} <li><a href="{% url acct-login %}">Log in</a></li> <li><a href="{% url acct-register %}">Register</a></li> {% endif %} </ul> It seems to work fine, unless the page been created has a @login_required decorator, in which case the page works fine but the navigation

Django 1.5: Accessing custom user model fields in models.py

折月煮酒 提交于 2019-12-07 04:06:52
问题 I'm working on a Django 1.5 project and I have a custom user model (let's call it CustomUser ). Another app (SomeApp) needs to reference this custom user model. For the purposes of ForeignKey and such, the Django documentation says to use User = settings.AUTH_USER_MODEL However, some functions in SomeApp.models need to access what would have formerly been known as User.objects . But User is now a string and not a class, so User.objects fails. The alternative would be from django.contrib.auth

User roles schema on Django

こ雲淡風輕ζ 提交于 2019-12-07 03:09:34
问题 A great greetings community My question is related with the kind of manage users and the schema users in Django, In beginning I ask to you apologize just in case that my questions can will be too "newbies" or without sense, I am starting to related me with the Django Users schemas and their different possibilities of work in the projects. I have the following situation. I am building an application in which I will have three differents user types: Medical Patient Physiotherapist I am using

Subclassing AbstractUser in Django for two types of users

▼魔方 西西 提交于 2019-12-06 16:54:14
问题 I'm developing a school database system in Django 1.5, and was planning on having a number of different user types (Student, Staff, Parent) which subclass AbstractUser (actually, another abstract subclass of AbstractUser). I was just attempting to add an externally developed app to my system, which uses User in a ForeignKey for some of its models, however, this fails as my user type is not a 'User' instance. I can't set the apps models to use AbstractUser as one can't use abstract classes for

In Django, when I call User.objects.create_user(username, email, password) - why does post_save get called twice?

倖福魔咒の 提交于 2019-12-06 11:42:22
In views.py I have the following view which gets called when a new user account is registered. All it does is get the username, email, and password from the request, then try to create a user with those credentials. In the code below, "A" gets printed, but "B" does not, because it crashes: views.py def register(request): if request.method == 'POST': query_dict = request.POST username = query_dict['username'] email = query_dict['user_email'] password = query_dict['password'] role = query_dict['role'] print "A" user = User.objects.create_user(username, email, password) # the handler is called

Django custom user model and usermanager

我怕爱的太早我们不能终老 提交于 2019-12-06 01:16:37
问题 i'm building a web application with Django 1.5. I'm using a custom User model with a custom UserManager. I followed the instructions and examples of the official Django documentation. Now, when i'm trying to create a new user via UserManager.create_user(...) i'm getting a NoneType error: It seems the UserManager's attribute models is of type None. I think i'm setting up the UserManager correctly in the User model ( objects = UserManager() ) I really don't know where i'm making a mistake.

ValueError in Django when running the “python manage.py migrate” command

余生颓废 提交于 2019-12-05 18:22:25
问题 I needed to add more fields to Django's User model, so I created a custom model class (named Accounts in an app named accounts ) that extends Django's AbstractUser class. After that, I updated my settings.py file, defining the AUTH_USER_MODEL property : AUTH_USER_MODEL = 'accounts.Accounts' I then created a migration file for the custom model using the python manage.py makemigrations command. After that, I ran the python manage.py migrate command and I got this error message: ValueError: The

Django user.is_authenticated works some places, not others

橙三吉。 提交于 2019-12-05 11:11:32
In my template, I have the following: <ul class="tabbed" id="network-tabs"> {% if user.is_authenticated %} <li><a href="{% url acct-my-profile %}">My Account</a></li> <li><a href="{% url acct-logout %}">Log Out</a></li> {% else %} <li><a href="{% url acct-login %}">Log in</a></li> <li><a href="{% url acct-register %}">Register</a></li> {% endif %} </ul> It seems to work fine, unless the page been created has a @login_required decorator, in which case the page works fine but the navigation appears as if the user is not logged in, even when they are. You should check your view function to see

Longer username in Django 1.7

孤街醉人 提交于 2019-12-05 10:17:58
I want to increase the length of the username in django from 30 to around 80, I know it may be duplicate question but the previous answers are not working, for example https://kfalck.net/2010/12/30/longer-usernames-for-django this is for Django 1.2. Did anyone try similar hack for Django>1.5 Thanks in advance In Django 1.5 and above, the recommended approach would be to create a custom user model . Then you can make the username field exactly as you want. I had the same problem few days ago. Finally, I ended just with cutting off first 30 characters of the (old) username (into the new database