2011-12-03 80 views
0

Django的新手。我對管理面板感到驚訝。任何人都可以推薦一個我可以分層的用戶註冊系統,就像一樣簡單嗎?包含視圖文件的優選文件。交鑰匙用戶註冊

回答

1

Django不像cms那樣只是插件的東西。但是它是非常容易地創建一個auth例行..只要閱讀文檔,瞭解這些文檔是很必要真正進入Django的業務:https://docs.djangoproject.com/en/1.3/topics/auth/

頁面上的例子會給你一個領先地位:

創建一個登錄和註冊表格視圖某處,然後再創建一個指向該視圖(表單操作)的URL,你就會有一個(非常)基本設置已經

class SignUpForm(forms.Form): 
    email = forms.EmailField(required=True, label=_("E-Mail")) 
    password = forms.CharField(required=True, label=_("Password"), widget=forms.PasswordInput) 
    password2 = forms.CharField(required=True, label=_("Repeat password"), widget=forms.PasswordInput) 
    first_name = forms.CharField(required=True, label=_("First name")) 
    last_name = forms.CharField(required=True, label=_("Last name")) 
    phone_number = forms.CharField(required=True, label=_("Phone number")) 

    return signup_form 

def sign_up(request): 
    """ 
    View for signing up a customer 
    """ 
    signup_form = customer_forms.SignUpForm(request.POST) 
    if signup_form.is_valid(): 
     create_user_and_login(request) 
     return #somewhere 
    else: 
     return #error handling 

def create_user_and_login(request): 
    ## Retrieve User data from form 
    email = request.POST["email"] 
    password = request.POST["password"] 
    first_name = request.POST["first_name"] 
    last_name = request.POST["last_name"] 
    ## Create a new user 
    new_user = User() 
    new_user.email = email 
    new_user.username = email 
    new_user.set_password(password) 
    new_user.first_name = first_name 
    new_user.last_name = last_name 
    new_user.save() 



from django.contrib.auth import authenticate, login 

def my_view(request): 
    username = request.POST['username'] 
    password = request.POST['password'] 
    user = authenticate(username=username, password=password) 
    if user is not None: 
     if user.is_active: 
      login(request, user) 
      # Redirect to a success page. 
     else: 
      # Return a 'disabled account' error message 
    else: 
     # Return an 'invalid login' error message. 

Ofcourse形式仍然需要清洗(見django文檔)永遠不要相信用戶輸入。