weixin_45909852
豚キムチ
2021-01-25 00:41

Django框架下提交表单没有任何反应

  • django
  • html5

视图文件: 

def new_topic(request):
    if request.method != 'POST':
        form = TopicForm()
        print("not post")
    else:
        form = TopicForm(request.POST)
        print("post")
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('http://www.baidu.com')
        else:
            print(form.errors.as_data()) # here you print errors to terminal

    context = {'form': form}
    return render(request, 'learning_logs/new_topic.html', context)

模板:

{% extends "learning_logs/base.html"%}

{%block content%}
<p>Add a new topic:</p>

<from action="{% url 'learning_logs:index'%}" method='post'>
    {% csrf_token %}
    {{form.as_p}}
    <input type="submit" value="Submit" />

</from>

{%endblock content%}

浏览器按下按钮后没有获取到任何的包,请问如何解决

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答

为你推荐

换一换