tags:

views:

42

answers:

1

I have a page, index.html, that contains both a login and registration form. I have a couple of questions about getting this to work properly

My URLConfig looks like this:

urlpatterns = patterns('djangoproject1.authentication.views',
    (r'^$',direct_to_template,{'template':'authentication/index.html'}),
    (r'^register/$','register'),
)

1) Using the Django book is a guide, my form looks like this:

<h1>Register</h1>
    <form action="/register/" method="post">
        {{ form.as_p }}
        <input type="submit" value="Register">
    </form>

Of course, since the file is index.html, the form doesn't appear when I just go to the page. Do I need a "view" to handle visiting index.html rather than a direct_to_template?

2) My Register code looks like this:

def register(request):
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            return HttpResponseRedirect("/register/success/")
        else:
            form = UserCreationForm()
    return render_to_response("authentication/index.html", {'form': form})

This is the django authentication built-in stuff. Do people actually use it? It seems limited. I know I can add more fields to the Django User by using a user profile or something, but what about the UserCreationForm? Should I roll my own form? Should it inherit from UserCreationForm somehow?

A: 

It sounds like you'll probably want to use a different generic view instead of direct_to_tepmlate. Take a look at the create object generic view. I usually just create a view, typically I end up needing to do more than what a generic view will allow me to do easily.

Matthew J Morrison