I wanted to show the user registration form in my project to the home page because I thought it is redundant to send user to another link of /accounts/register because I want to encourage them to signup right from home page. I spent almost 2 full days trying different things and finally found the solution which is so simple and easy. The trick is using Django’s class based views. Here is my solution and I hope it can help other people. By the way I’m using module registration-redux in the app.
from registration.backends.default.views import RegistrationView
class IndexView(RegistrationView):
template_name = "myapp/index.html"
url(r'^$', views.IndexView.as_view(), name="home"),
index.html
<form method="post" action="." class="col-xs-4">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
Note: If you are using Django’s built-in user registration process, then simply change the views.py to following:
from django.contrib.auth.forms import UserCreationForm
from django.views.generic import CreateView
class IndexView(CreateView):
form_class = UserCreationForm
template_name = "myapp/index.html"
Thanks and please let me know if someone has a question.