Django 报错 Reverse for 'content' not found. 'content' is not a valid view function or pattern name.

时间:2023-03-09 01:24:10
Django 报错 Reverse for 'content' not found. 'content' is not a valid view function or pattern name.

Django 报错 Reverse for 'content' not found. 'content' is not a valid view function or pattern name.

Django 报错 Reverse for 'content' not found. 'content' is not a valid view function or pattern name.

  • 我这边的原因是由于命名空间的错误导致的bug
from django.urls import path
from . import views app_name = 'energy' # 给app命名空间 urlpatterns = [
path('search/', views.search, name='search'), # 给视图函数分配命名空间
path('content/', views.content, name='content')
]
  • 这样下面就可以使用了!
<form action="{% url 'energy:content' %}" method="POST">
{% csrf_token %}
<div>
<label>
<input type="text" name="搜索内容">
</label>
<input type="submit" value="搜索">
</div>
</form>