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)!