You are not logged in.

Change Language:

Freelancer? Consultant? Check out: WorkTrail - Time Tracking made easy
Board » Django Standard Library » Authentication » Resources for Frontend dev

Newbie need stuff. I am working on my first django site, so far all“s been smooth following the tutorials, the admin backend is all good for now, and now Im working on user authentication. I followed this tutorial: http://codingnstuff.com/2010/01/create-your-user-management-frontend-in-django/ which was full of little errors, but i managed to correct them for the most part. However, Im stuck on the user activation and login functions. I am looking for either simple tutorials or sample files to get me past these newbie hurdles. In other words, anyone have or know of other resources for creating a user authentication frontend? Of course Ive been going thru the documentation (http://docs.djangoproject.com/en/dev/topics/auth/), but an example of usage would really be nice to get me started.

Any advice would be much appreciated!
i think the example code in the tutorial does exactly what you are looking for: http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.login

from django.contrib.auth import authenticate, login

def my_view(request):
    username = request.POST['username']
    password = request.POST['password']
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            login(request, user)
            # Redirect to a success page.
        else:
            # Return a 'disabled account' error message
    else:
        # Return an 'invalid login' error message.


an example HTML frontend would look like:

  <form method="post" action="/myurl/my_view/">
  Username: <input type="text" name="username" />
  Password: <input type="password" name="password" />
  <input type="submit" value="Login" />
  </form>

Thanks for quick reply Herbert! Yea, Im making progress with the django documentation, and even more so the django book http://www.djangobook.com/en/1.0/chapter12/. Just looking for a something more tutorial-ish, since Im new at this. But I'll keep trudging along with the documentation, thanks again...
Well it seems I managed to figure it all out after much reading and trial and error, ah yes love the first feeling of Noob success :)

Perhaps I should make a new thread for this, but I will ask here while Im at it. Now I would like to make user groups, but not necessarily in the manner of group permissions. What I need to do is basically make a sub-set of users under a main user profile, where the admin will assign and associate content with a set users (ie a group). For example, the admin creates/selects a group in the backend, and uploads a static media file, associating it with the group. Then a user within this group logs on and may access the media file. An example application could be a chain of restaurants that share the same base content, but each individual restaurant has it's own user to access and edit the content to their specific needs.

Do you think I have to extend the user model to do this, or is there a way to make user groups or sub-users, or perhaps using django's group permission architecture can do this sufficiently?

i think you have to create your own system for this.. simply create a 'UserSet' model which has a n:m relation to django's 'User' object.. if what you need is that a user can only be in one group you could also create a model which mirrors the django User .. something like.. MyUser which as a 1:1 relation to django User model and a simple ForeignKey (1:n) relation to a UserSet.. 1:1 relations and 1:n relations are very easy to create in django and easy to work with..
hope this makes some kind of sense to you
Ok, yes I think I get the idea. Yea exactly, a user belongs only to one group, so the "mirror" option using a foreignkey relation seems like the way to go. Great, thanks for the advice, time to get crackin'.





Powered by Sphene Community Tools