I
I
Isaac Clark2012-07-11 12:55:06
Django
Isaac Clark, 2012-07-11 12:55:06

How to make the registration form and the login form on the same page?

Hello.
Tell me please.
There is a registration form and an entrance to the site, which are located on the same page and have one urls.

#urls.py
urlpatterns = patterns('users.views',   
    url(r'^$', 'PersonRegistration', name = 'Home Page'),   
    url(r'^$', 'LoginRequest', name = 'Home Page'),    
)

Both of them are in the same views
#views.py
def PersonRegistration(request):
    ...

def LoginRequest(request):
    ...

Registration works, everything is super! But… As soon as I connect the LoginRequest and try to log in as a registered user through it, the PersonRegistration registration form also starts to be processed…
How can I separate the forms and make sure that only the one that is needed is processed.
action=""
We really need your help, dear experts…
Thank you

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Andrey Burov, 2012-07-11
@BuriK666

<form>
<input type="hidden" name="form" value="registration" />
</form>

<form>
<input type="hidden" name="form" value="auth" />
</form>

A
Anatoly, 2012-07-11
@taliban

And I would advise you to separate these two pages =) After all, they do different things, why sculpt everything in one place?

M
marazmiki, 2012-07-11
@marazmiki

Some wildness.
What for to process registration and an input in one? Okay, you can display both forms on one page, if it really itchs. But to process!

M
marazmiki, 2012-07-11
@marazmiki

The easiest way is to make a separate page with both forms. Output only, no processing.
First write the view:

from django.shortcuts import render
def all_in_one(request):
    return render('reg_and_login.html', {
        'login_form': LoginForm(),
        'register_form': RegistrationForm()
    })

Then add it to those already announced. Pay special attention to ensure that registration and entry are entered on different urls:
url(r'^$', 'all_in_one'), # Добавили
url(r'^registration/$', 'PersonRegistration', name = 'register-form'), # Изменили
url(r'^login$', 'LoginRequest', name = 'login-form'),  # Изменили

And make a template (this code is taken from larikov 's answer ):
<!-- reg_and_login.html -->
<form action="{% url login-form %}" method="post">
    {{ login_form }}
</form>

<form action="{% url register-form %}" method="post">
     {{ register_form }}
</form>

L
larikov, 2012-07-11
@larikov

I'm more interested in how in your case django knows which view to display?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question