English: Gmail registration screenshots فارسی: عکسهای برگه ثبتنام جیمیل (Photo credit: Wikipedia) |
Django registration module is quite handy whenever you need some users to, well, registrate to your website… In this post, I will explain you how to install and configure it for your web app.
To install django registration module:
easy_install -Z django-registration
The documentation is in the docs folder (quickstart.rst) and is also available online: https://bitbucket.org/ubernostrum/django-registration/src/27bccd108cdef30dc0a91ed1968be17bb1e60da4/docs/quickstart.rst?at=default
django-registration’s role is to permit the creation of new users, which means according to the documentation:
- A user signs up for an account by supplying a username, email address and password.
- From this information, a new User object is created, with its is_active field set to False. Additionally, an activation key is generated and stored, and an email is sent to the user containing a link to click to activate the account.
- Upon clicking the activation link, the new account is made active (the is_active field is set to True); after this, the user can log in.
For this part, I used the following tutorial.
I add ‘registration’ to my INSTALLED_APPS in settings.py
I add ACCOUNT_ACTIVATION_DAYS = 7 in my settings.py
I define all the mail parameters in settings.py:
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'yourpassword'
EMAIL_PORT = 587
I add (r’^accounts/’, include(‘registration.urls’)), to urls.py
I modify my base.html template to add links to the registration page
{% if not user.is_authenticated %}<li><a href=”{% url ‘login’ %}”>Log in</a></li>
<li><a href=”{% url ‘registration_register’ %}”>Register</a></li>
{% endif %}
{% if user.is_authenticated %}
Logged in: {{ user.username }}
(Log out |
Change password)
{% endif %}
I create the required registration templates in templates/registration/ according to the examples provided in http://lightbird.net/dbe/forum3.html
activate.html
activation_complete.html
activation_email.txt
activation_email_subject.txt
login.html
registration_complete.html
registration_form.html
Note that in the template, whenever I need to refer to django-registration urls, I need to know a name to put in my {% url %} tags. I found the appropriate names here: http://code.google.com/p/django-registration/source/browse/trunk/registration/urls.py?r=169
Finally, I check if the register link defined above works. At first I had a URL problem after filling the register form and submitting it. I solved it by editing the registration/registration_form.html file to change the form submission url.
Leave a Reply