这是我收到错误的代码。我正在尝试在模板中添加肥料名称URL,但出现错误“ Django.urls.exceptions.NoReverseMatch:找不到“肥料名称”的反向符号。“肥料名称”不是有效的视图函数或模式名称。”
urls.py:
from django.urls import path
from .views import findex,predict_chances,view_results
app_name = "fertilizer"
urlpatterns=[
path('', findex, name='fertilizer-name'),
path('fertilizer/',predict_chances,name='submit_prediction'),
path('fertilizer/results/',view_results,name='results'),
]
views.py:
def findex(request):
context={'name':'fertilizer'}
return render(request,'fertilizer/index.html',context)
模板:
<div class="col-md-6 col-sm-12">
<div class="shop-cat-box">
<a href="{% url 'fertilizer-name' %}"><img class="img" src="{% static 'images/cyp/3.png' %}" alt="" /></a>
</div>
</div>