I'm trying to render two forms (signup and login) on the same page in Django. I want to POST the data to either field by changing the <form action="some_url"
tag. It's the first suggestion in this answer: https://stackoverflow.com/a/1395866/2532070
Is this possible? Currently I have:
urls.py:
url(r'^', HomePageView.as_view()),
url(r'^signup/$', SignupUser.as_view(), name="signup_user"),
views.py:
class HomePageView(View):
template_name = "index.html"
login_form = AuthenticationForm()
signup_form = UserCreationForm()
def get(self, request, *args, **kwargs):
return render(request, self.template_name, {
'login_form': self.login_form,
'signup_form': self.signup_form,
'signup_action': reverse("signup_user")}
)
class SignupUser(CreateView):
model = settings.AUTH_USER_MODEL
form_class = UserCreationForm
my template:
<form action="{{ signup_action }}" method="POST">{% csrf_token %}
{{ signup_form }}
<input type="submit" value="Signup">
</form>
Unfortunately, the POST seems to be calling the post function of HomePageView
, rather than calling the SignupUser
view.
Is it possible to call my SignupUser view with the POST data by correctly formatting my form's action="..."
tags?