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

Source: Internet
Author: User

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

This article describes how to use the Django-userena component in Python, including the implementation of simple functions such as user login and registration. For more information, see

Using twitter/bootstrap, the basic template of the Project is handled smoothly. 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.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

Forms. py

# Add BootstrapMixin to the original form

From bootstrap. forms import BootstrapMixin

 

Class BsAuthenticationForm (AuthenticationForm, BootstrapMixin ):

Def _ init _ (self, * args, ** kw ):

Super (BsAuthenticationForm, self). _ init _ (* args, ** kw)

Self. _ bootstrap __()

 

Urls. py

# Override urls and specify the form used

From django. conf. urls. defaults import *

From userena import views as userena_views

From profiles. forms import BsSignupForm, BsAuthenticationForm

 

Urlpatterns = 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.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

USERNAME_RE = R' ^ \ S + $'

Attrs_dict = {'class': 'requestred '}

 

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 __()

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.