A simple tutorial on Django-userena components in Python's Django

Source: Internet
Author: User
With Twitter/bootstrap, the foundation template for the project is a smooth fix. Next, start working with the User Center.

User Center mainly includes user login, registration and Avatar and other personal information maintenance. Previously, the user's registration management I have been using django-registration. But this app is a little bit enterprising, 09 released 0.8alpha version has been no movement. This decision tries another user module component Django-userena.

Compared to the Django-registration,django-userena function to improve the more. In addition to the basic login registration module Django-userena Even with the station message function. Django-userena is also doing very well in terms of ease of use. Django-userena comes with a default template and has a complete demo project that you can easily get started with. Here is an official online demo, interested to see.
Integration of Django-userena with Twitter/bootstrap

We naturally want all the apps to be used without any changes. But it backfired, in the process of integration more or less encountered some problems. Django-userena The default template is very ugly to display in the project. We need to rewrite the default template for Django-userena and use Django-bootstrap to generate the form.

forms.py# add bootstrapmixinfrom bootstrap.forms import Bootstrapmixinclass bsauthenticationform for the original form ( Authenticationform, Bootstrapmixin): Def __init__ (self, *args, **kw):  super (Bsauthenticationform, self). __init__ (*args, **kw)  self.__bootstrap__ () urls.py# rewrite URLs, specifying 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 ')),)

Chinese User name problem

Like Django-admin, Django-userena is not able to register with Chinese. For a Chinese website, the inability to use the Chinese registration ID seems a bit unreasonable.

Django-userena uses regular expressions to verify the user name and rewrite the registration form to modify the authentication rule to cancel the restriction.

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 the content of the simple use tutorial for Django-userena components in Python's Django, and more about topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.