当前位置: 首页>>代码示例>>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;未经允许,请勿转载。