【发布时间】:2018-01-24 23:29:33
【问题描述】:
出现错误:NoReverseMatch:未找到“post_new”的反向。 'post_new' 不是有效的视图函数或模式名称。
我在 base.html 中的表单:
> <form action="{% url 'post_new' %}" method="post">
> {% csrf_token %}
> Name:<br>
> <input type="text" name="name"><br>
> Text:<br>
> <input type="text" name="text">
> <input type="submit" value="Submit">
</form>
views.py:
def post_new(request):
posts = Post.objects.all()
name = request.POST['name']
print(name)
return render(request, 'blog/base.html', {'posts': posts})
urls.py:
urlpatterns = [
url(r'^$', views.base),
url(r'^post_new/$', views.post_new, name='post_new'),
]
【问题讨论】:
-
如果将
action="{% url 'post_new' %}"替换为action="."会发生什么?
标签: python django web django-forms