This article mainly introduces the Python Django Django-userena components of the simple use of the tutorial, including user login and registration, such as the implementation of simple functions, need friends can refer to the
Using Twitter/bootstrap, the project's underlying template is well done. The next step is to start processing 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, and after the release of the 0.8alpha version in 09, nothing has happened. This time I decided to try another user module component Django-userena.
Compared to the Django-registration,django-userena function to be more perfect. In addition to the basic landing registration module outside the Django-userena even with the station message function. Django-userena is also doing very well in terms of ease of use. Django-userena has its own default templates and offers 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 hope that all apps will not have to be modified and used. But it backfired, in the process of integration more or less will encounter some problems. Django-userena The default template appears very ugly in the project. We need to rewrite the Django-userena default template and use Django-bootstrap to generate the form.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21-22 |
forms.py #为原始form添加BootstrapMixin from bootstrap.forms Import Bootstrapmixin class Bsauthenticationform ( Authenticationform, Bootstrapmixin): Def __init__ (self, *args, **kw): Super (Bsauthenticationform, self). __init__ (* args, **kw) self.__bootstrap__ () urls.py #重写urls, specifying the form from django.conf.urls.defaults Import * from Userena Import V Iews as Userena_views from profiles.forms import bssignupform, bsauthenticationform urlpatterns = Patterns (', url (r ' ^si Gnup/$ ', 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 ')) |
User name problem in Chinese
Like Django-admin, Django-userena is not allowed to register in Chinese. For a Chinese website, it seems too unreasonable to use the Chinese registration ID.
Django-userena uses regular expressions to validate user names and rewrite the registration form to modify the authentication rules to remove the restriction.
?
1 2 3 4 5 6 7 8 9 10 11 12-13 |
Username_re = R ' ^s+$ ' attrs_dict = {' class ': ' Required '} class Bssignupform (Signupform, bootstrapmixin): USERNAME = Form S.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__ () |