A simple tutorial on using the Django-userena component in Python django

Source: Internet
Author: User
This article mainly introduces a simple tutorial on using the Django-userena component in Python, including the implementation of simple functions such as user login and registration. if you need it, refer to using twitter/bootstrap, the basic template of the project is successfully completed. Next, process the user Center.

The user center mainly includes personal information maintenance such as user login, registration, and profile picture. Previously, I used django-registry for user registration management. It's just that this APP is a bit aggressive. after the 0.8alpha version was released in, there has been no movement. This time I decided to try another user module component django-userena.

Compared with django-registration, django-userena has more comprehensive functions. In addition to the basic login and registration module, django-userena even provides the station message function. Django-userena is also doing very well in terms of ease of use. Django-userena comes with the default template and provides a complete demonstration project, so that you can easily get started. Here is an official online demo. if you are interested, go and check it out.
Integration of django-userena with twitter/bootstrap

We naturally hope that all apps can be used without any modifications. However, contrary to expectations, some problems may occur in the integration process. The default django-userena template is very ugly in the project. We need to rewrite the default template of django-userena and use django-bootstrap to generate a form.

Forms. py # Add BootstrapMixinfrom bootstrap to the original form. forms import BootstrapMixinclass BsAuthenticationForm (AuthenticationForm, BootstrapMixin): def _ init _ (self, * args, ** kw): super (BsAuthenticationForm, self ). _ init _ (* args, ** kw) self. _ bootstrap _ () urls. py # Rewrite urls to specify the formfrom django. conf. urls. defaults import * from userena import views as userena_viewsfrom profiles. forms import BsSignupForm, BsAuthenticationFormurlpatterns = patterns ('', url (r' ^ signup/$ ', userena_views.signup, {'signup _ form': BsSignupForm }, name = 'userena _ signup'), url (r' ^ signin/$ ', userena_views.signin, {'auth _ form': BsAuthenticationForm}, name = 'userena _ signin '), (r ^_^ _ ^ ', include ('userena. urls ')),)

Questions about Chinese user name

Like django-admin, django-userena cannot be registered in Chinese. It seems unreasonable for a Chinese website to use a Chinese registration ID.

Django-userena uses regular expressions to verify the user name. you can cancel this restriction by rewriting the registration form to modify the authentication rules.

USERNAME_RE = r'^\S+$'attrs_dict = {'class': 'required'}class BsSignupForm(SignupForm, BootstrapMixin): username = forms.RegexField(regex=USERNAME_RE,        max_length=30,        widget=forms.TextInput(attrs=attrs_dict),        label=_("Username"),        error_messages={'invalid': _('Username must contain only letters, numbers, dots and underscores.')}) def __init__(self, *args, **kw):  super(BsSignupForm, self).__init__(*args, **kw)  self.__bootstrap__()

The above is a simple tutorial on using the Django-userena component in Python django. For more information, see The PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.