Hi oliver!

With appenginepatch, when you import this:

from django.contrib.auth.models import User

you will have a User object that is very similar to the Django User model.

I use this with appenginepatch:

view-code:
from google.appengine.ext.webapp import template
import django.forms as forms
from django.contrib.auth.models import User
from django.shortcuts import render_to_response
from django.http import *

class LoginForm(forms.Form):
    username = forms.CharField(label = "Username", max_length=30)
    passwort = forms.CharField(label = "Password",
widget=forms.widgets.PasswordInput(), max_length=30)

def login(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect("/")
    errors = ""
    form = LoginForm()
    if request.method == "POST":
        next = request.GET.get("next", "/")
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            passwort = form.cleaned_data['passwort']
            user = auth.authenticate(username = username, password = passwort)
            if user is not None and user.is_active:
                auth.login(request, user)
                return HttpResponseRedirect(next)
            else:
                errors = "Can't log you in. Wrong password?"
    return render_to_response("login/user.html",
RequestContext(request, {'form': form, 'errors': errors}))

I hope I didn't forget any imports, I have split the code over several files.
In the template, you can just do

<form action='.' method='post'>
{{form.as_p}}
</form>

or

<form action='.' method='post'>
{% if form.username.errors %}
<p class="error"> {{ form.username.errors }} </p>
{% endif %}

<table align="center">
<tr>
<td>
{{form.username.label}}
</td>
<td>
{{form.username}}

...

Hope this helps you!

Best Regards,

Jesaja Everling



On Fri, Nov 21, 2008 at 11:29 AM, oliver <[EMAIL PROTECTED]> wrote:
>
> Can someone direct me towards the steps I need to take to integrate
> the Django user authentication code into my GAE application.
>
> The first step seem to be to download the app-engine-django-patch and
> use the sample application.
>
> That appears to give me Django in GAE but then I don't see how to add
> the user registration/authentication code.
>
> Then (sorry) once I have the right code in place, is there some sample
> code that illustrates how to write the Django template code to allow
> users to register/sign in.
>
> I know this seems like I'm being lazy but I don't know GAE, Django or
> Python - someone will probably tell me implement things differently -
> but I want to learn - this kind of Web application development is
> clearly the future.
>
> Thanks
>
> oliver.
>
> >
>



-- 
o
L_/
OL
This is Schäuble. Copy Schäuble into your signature to help him on his
way to Überwachungsstaat.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to