开发者

How to view all the users that have signed up for a certain website in django?

I am using django-auth , thus all the usernames ar开发者_JAVA技巧e stored there . How do I retrieve all these users in a different app , to apply certain privileges to it ? Like databrowse admin , is there any way to browse the users (usernames) too ?


If you don't know how to do a query in Django, you shouldn't be trying to get django-auth working, or trying to change privileges or use the admin. Walk before you can run.

If you had a model (i.e. a table in the database) representing People:

class Person(model.Model):
    name = models.CharField(max_length=100)

how would you go about getting all of the people in your database? You'd use:

all_people = Person.objects.all()

to get a person with a particular name? Try:

joe = Person.objects.get(name__exact="joe")

so on. It's the same for django-auth's users.

from django.auth.models import User
users = User.objects.all()
for user in users:
    print user.username

Forget about applying privileges to anything. Concentrate on learning the absolute basics of Django, Querying and the ORM before you do anything else.

http://www.djangobook.com/en/2.0/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜