當前位置: 首頁>>代碼示例>>Python>>正文


Python forms.UserCreationForm方法代碼示例

本文整理匯總了Python中django.contrib.auth.forms.UserCreationForm方法的典型用法代碼示例。如果您正苦於以下問題:Python forms.UserCreationForm方法的具體用法?Python forms.UserCreationForm怎麽用?Python forms.UserCreationForm使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.contrib.auth.forms的用法示例。


在下文中一共展示了forms.UserCreationForm方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: user_add

# 需要導入模塊: from django.contrib.auth import forms [as 別名]
# 或者: from django.contrib.auth.forms import UserCreationForm [as 別名]
def user_add(request):
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            uid = Student.objects.latest('pk').pk
            return redirect('user_edit', pk=uid)
    else:
        form = UserCreationForm()

    print(form.errors)

    if request.user.is_authenticated and request.user.is_superuser:
        return render(
            request, 'user_add.html', {'form': form},
        )
    else:
        return redirect('login') 
開發者ID:urankajtazaj,項目名稱:SEMS,代碼行數:20,代碼來源:views.py

示例2: signup

# 需要導入模塊: from django.contrib.auth import forms [as 別名]
# 或者: from django.contrib.auth.forms import UserCreationForm [as 別名]
def signup(request):
    if request.user.is_authenticated:
        return HttpResponseRedirect('/post/')
    if request.method == 'GET':
        form = UserCreationForm()
        return render(request, 'tilweb/signup.html', {'form': form})
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            # https://docs.djangoproject.com/en/1.11/topics/forms/modelforms/#the-save-method
            form.save()
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=password)
            login(request, user)
            return HttpResponseRedirect('/post/')
        else:
            # If there were errors, we render the form with these
            # errors
            return render(request, 'tilweb/signup.html', {'form': form}) 
開發者ID:amitsaha,項目名稱:python-monitoring-talk,代碼行數:22,代碼來源:views.py

示例3: register_view

# 需要導入模塊: from django.contrib.auth import forms [as 別名]
# 或者: from django.contrib.auth.forms import UserCreationForm [as 別名]
def register_view(request):
    redirect_path = request.GET['r'] if request.GET.get('r', '').startswith('/editor/') else reverse('editor.index')
    if request.user.is_authenticated:
        return redirect(redirect_path)

    if request.method == 'POST':
        form = UserCreationForm(data=request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            return redirect(redirect_path)
    else:
        form = UserCreationForm()

    form.fields['username'].max_length = 20
    for field in form.fields.values():
        field.help_text = None

    return render(request, 'editor/account_form.html', {
        'title': _('Create new account'),
        'back_url': reverse('site.login'),
        'form': form
    }) 
開發者ID:c3nav,項目名稱:c3nav,代碼行數:25,代碼來源:account.py

示例4: signup

# 需要導入模塊: from django.contrib.auth import forms [as 別名]
# 或者: from django.contrib.auth.forms import UserCreationForm [as 別名]
def signup(request):
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('books')
    else:
        form = UserCreationForm()
    return render(request, 'signup.html', {'form': form}) 
開發者ID:OmkarPathak,項目名稱:Django-Bookworm,代碼行數:15,代碼來源:views.py

示例5: __init__

# 需要導入模塊: from django.contrib.auth import forms [as 別名]
# 或者: from django.contrib.auth.forms import UserCreationForm [as 別名]
def __init__(self, *args, **kwargs):
        super(CssUserCreationForm, self).__init__(*args, **kwargs)
        self.label_suffix = ''
        self.fields['username'].widget.attrs['class'] = 'form-control'
        self.fields['email'].widget.attrs['class'] = 'form-control'
        self.fields['password1'].widget.attrs['class'] = 'form-control'
        self.fields['password2'].widget.attrs['class'] = 'form-control'

    # UserCreationForm doesn't include email, so we add it and make it required 
開發者ID:tramcar,項目名稱:tramcar,代碼行數:11,代碼來源:forms.py

示例6: login

# 需要導入模塊: from django.contrib.auth import forms [as 別名]
# 或者: from django.contrib.auth.forms import UserCreationForm [as 別名]
def login(request):
    if request.user.is_authenticated:
        messages.add_message(
            request, messages.INFO, message=_("You are already logged in.")
        )
        return redirect("home")

    context = {"login_form": AuthenticationForm(), "signup_form": UserCreationForm()}
    if request.method == "POST":
        if request.POST.get("action") == "login":
            login_form = AuthenticationForm(data=request.POST)
            if login_form.is_valid():
                username = login_form.cleaned_data.get("username")
                raw_password = login_form.cleaned_data.get("password")
                user = authenticate(username=username, password=raw_password)
                login_user(request, user, backend=user.backend)
                return redirect("home")
            else:
                context["login_form"] = login_form
                context["action"] = "login"
        elif request.POST.get("action") == "signup":
            signup_form = UserCreationForm(data=request.POST)
            if signup_form.is_valid():
                signup_form.save()
                username = signup_form.cleaned_data.get("username")
                raw_password = signup_form.cleaned_data.get("password1")
                user = authenticate(username=username, password=raw_password)
                login_user(request, user, backend=user.backend)
                return redirect("home")
            else:
                context["signup_form"] = signup_form
                context["action"] = "signup"

    return render(request, "get_together/users/login.html", context) 
開發者ID:GetTogetherComm,項目名稱:GetTogether,代碼行數:36,代碼來源:user.py

示例7: register_view

# 需要導入模塊: from django.contrib.auth import forms [as 別名]
# 或者: from django.contrib.auth.forms import UserCreationForm [as 別名]
def register_view(request):
    if not settings.USER_REGISTRATION:
        return HttpResponse(_('account creation is currently disabled.'), content_type='text/plain', status=403)

    if request.user.is_authenticated:
        return close_response(request)

    if request.method == 'POST':
        form = UserCreationForm(data=request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            redeem_token_after_login(request)
            return close_response(request)
    else:
        form = UserCreationForm()

    form.fields['username'].max_length = 20
    for field in form.fields.values():
        field.help_text = None

    return render(request, 'site/account_form.html', {
        'title': _('Create new account'),
        'back_url': reverse('site.login'),
        'form': form
    }) 
開發者ID:c3nav,項目名稱:c3nav,代碼行數:28,代碼來源:views.py

示例8: register

# 需要導入模塊: from django.contrib.auth import forms [as 別名]
# 或者: from django.contrib.auth.forms import UserCreationForm [as 別名]
def register(request):
    """new user register page

    :request: client request
    :returns: redirect to login page if success else register page

    """
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            return HttpResponseRedirect('/accounts/login/')
    else:
        form = UserCreationForm()
    return render(request, 'register.html', locals()) 
開發者ID:its-django,項目名稱:mysite,代碼行數:17,代碼來源:views.py

示例9: test_displays_signup_form

# 需要導入模塊: from django.contrib.auth import forms [as 別名]
# 或者: from django.contrib.auth.forms import UserCreationForm [as 別名]
def test_displays_signup_form(self):
        response = self.client.get(self.signup_url)
        self.assertIsInstance(response.context["form"], UserCreationForm)
        self.assertContains(response, 'name="password2"') 
開發者ID:project-callisto,項目名稱:callisto-core,代碼行數:6,代碼來源:test_views.py

示例10: sign_up

# 需要導入模塊: from django.contrib.auth import forms [as 別名]
# 或者: from django.contrib.auth.forms import UserCreationForm [as 別名]
def sign_up(request):
    form = UserCreationForm()
    if request.method == 'POST':
        form = UserCreationForm(data=request.POST)
        if form.is_valid():
            form.save()
            return redirect(reverse('example:log_in'))
        else:
            print(form.errors)
    return render(request, 'example/sign_up.html', {'form': form}) 
開發者ID:realpython,項目名稱:django-example-channels,代碼行數:12,代碼來源:views.py

示例11: __init__

# 需要導入模塊: from django.contrib.auth import forms [as 別名]
# 或者: from django.contrib.auth.forms import UserCreationForm [as 別名]
def __init__(self, *args, **kwargs):
        super(UserCreationForm, self).__init__(*args, **kwargs)
        self.fields['username'].widget.attrs.pop('autofocus', None) 
開發者ID:iguana-project,項目名稱:iguana,代碼行數:5,代碼來源:forms.py

示例12: register_account

# 需要導入模塊: from django.contrib.auth import forms [as 別名]
# 或者: from django.contrib.auth.forms import UserCreationForm [as 別名]
def register_account(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect("index")

    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.save()

            UserProfile.objects.create(
                username=user.username,
                name=request.POST.get('name',''),
                affiliation=request.POST.get('affiliation',''),
                level='normal',
                email=request.POST.get('email', ''),
            )

            user = authenticate(username=request.POST['username'],
                         password=request.POST['password1'])
            login(request, user)
            return HttpResponseRedirect("index")
    else:
        form = UserCreationForm()

    return render_to_response("registration/account.html", RequestContext(request,
        {
            'form' : form,
            'which_page' : "register"
        })) 
開發者ID:jeanqasaur,項目名稱:jeeves,代碼行數:32,代碼來源:views.py

示例13: register_account

# 需要導入模塊: from django.contrib.auth import forms [as 別名]
# 或者: from django.contrib.auth.forms import UserCreationForm [as 別名]
def register_account(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect("index")

    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.save()

            UserProfile.objects.create(
                username=user.username,
                email=request.POST.get('email', ''),
            )

            user = authenticate(username=request.POST['username'],
                         password=request.POST['password1'])
            login(request, user)
            return HttpResponseRedirect("index")
    else:
        form = UserCreationForm()

    return render_to_response("registration/account.html"
        , RequestContext(request,
        {'form': form,
        'which_page' : "register"})) 
開發者ID:jeanqasaur,項目名稱:jeeves,代碼行數:28,代碼來源:views.py

示例14: register_account

# 需要導入模塊: from django.contrib.auth import forms [as 別名]
# 或者: from django.contrib.auth.forms import UserCreationForm [as 別名]
def register_account(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect("index")

    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.save()

            User.objects.create(
                username=user.username
              , email=request.POST.get('email', '')
              , name=request.POST.get('name', '')
              , role=request.POST.get('role', '')
            )

            user = authenticate(username=request.POST['username'],
                         password=request.POST['password1'])
            login(request, user)
            return HttpResponseRedirect("index")
    else:
        form = UserCreationForm()

    return render_to_response("registration/account.html", RequestContext(request,
        {
            'form' : form,
            'which_page' : "register"
        })) 
開發者ID:jeanqasaur,項目名稱:jeeves,代碼行數:31,代碼來源:views.py

示例15: register_account

# 需要導入模塊: from django.contrib.auth import forms [as 別名]
# 或者: from django.contrib.auth.forms import UserCreationForm [as 別名]
def register_account(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect("index")

    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.save()

            UserProfile.objects.create(
                username=user.username,
                email=request.POST.get('email', ''),
            )

            user = authenticate(username=request.POST['username'],
                         password=request.POST['password1'])
            login(request, user)
            return HttpResponseRedirect("index")
    else:
        form = UserCreationForm()

    return render_to_response("registration/account.html", RequestContext(request,
        {
            'form' : form,
            'which_page' : "register"
        })) 
開發者ID:jeanqasaur,項目名稱:jeeves,代碼行數:29,代碼來源:views.py


注:本文中的django.contrib.auth.forms.UserCreationForm方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。