def post(self, request):
        form = CategoryForm(request.POST)

        if form.is_valid():
            form.save(commit=True)
            return IndexView().get(request)
        else:
            print(form.errors)

        return render(request, 'rango/add_category.html', {'form': form})
Example #2
0
def add_category(request):
    if request.method == 'POST':
        form = CategoryForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            return index(request)
        else:
            print form.errors
    else:
        form = CategoryForm()
    return render(request,'rango/add_category.html',{'form':form})
Example #3
0
def add_category(request):
    form = CategoryForm()

    if request.method == "POST":
        form = CategoryForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            return index(request)
        else:
            print(form.errors)
    return render(request, 'rango/add_category.html', {'form': form})
Example #4
0
def add_category(request):
    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(request.POST)

        # Have we been provided with a valid form?
        if form.is_valid():
            # Save the new category to the database.
            form.save(commit=True)

            # Now call the index() view.
            # The user will be shown the homepage.
            return index(request)
        else:
            # The supplied form contained errors - just print them to the terminal.
            print form.errors
    else:
        # If the request was not a POST, display the form to enter details.
        form = CategoryForm()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    return render(request, 'rango/add_category.html', {'form': form})
Example #5
0
def add_category(request):
    form = CategoryForm()
    print("add!")
    #是HTTP POST请求吗?
    if request.method == 'POST':
        form = CategoryForm(request.POST)
        #
        if form.is_valid():
            print(form)
            form.save(commit=True)
            return index(request)
        else:
            print(form.errors)

    return render(request, 'rango/add_category.html', {'form': form})
Example #6
0
def add_category(request):
    # 实例化
    form = CategoryForm()
    # 判断请求类型
    if request.method == 'POST':
        form = CategoryForm(request.POST)
        print("是")

        if form.is_valid():
            form.save(commit=True)
            # 返回首页
            return index(request)
        else:
            print(form.errors)
    print("get方法")
    # 渲染表单,并显示可能出现的错误to html 编写页面表单
    return render(request, 'rango/page.html', {'form': form})
Example #7
0
def add_category(request):
    # HTTP POST
    if request.method == 'POST':
        form = CategoryForm(request.POST)
        # Have we been provided with a valid form?
        if form.is_valid():
            # Save the new category to the database.
            form.save(commit=True)
            # Now call the index() view.
            # The user will be shown the homepage.
            return index(request)
        else:
            print form.errors
    else:
        # If the request was not a POST, display the form to enter details
        # If there are errors, redisplay the form with error messages.
        form = CategoryForm()
    return render(request, 'rango/add_category.html', {'form': form})
Example #8
0
def add_category(request):
    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(request.POST)

        # Have we been provided with a valid form?
        if form.is_valid():
            # Save the new category to the database.
            form.save(commit=True)

            # Now call the index() view.
            # The user will be shown the homepage.
            return index(request)
        else:
            # The supplied form contained errors - just print them to the terminal.
            print form.errors
    else:
        # If the request was not a POST, display the form to enter details.
        form = CategoryForm()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    return render(request, 'rango/add_category.html', {'form': form})
 def get(self, request):
     form = CategoryForm()
     return render(request, 'rango/add_category.html', {'form': form})