示例#1
0
def add_token(request):
    context = {}
    form = forms.AddTokenForm()
    if request.method == 'POST':
        form = forms.AddTokenForm(request.POST)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.user = form.cleaned_data['user']
            instance.save()
            messages.success(request, 'Token created.')
            return redirect('kegadmin-tokens')
    context['form'] = form
    return render(request, 'kegadmin/add_token.html', context=context)
示例#2
0
def add_token(request):
    context = {}
    form = forms.AddTokenForm()
    if request.method == "POST":
        form = forms.AddTokenForm(request.POST)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.user = form.cleaned_data["user"]
            instance.save()
            messages.success(request, "Token created.")
            return redirect("kegadmin-tokens")
    context["form"] = form
    return render(request, "kegadmin/add_token.html", context=context)