在向按钮添加 link 时,当前路径与这些错误中的任何一个都不匹配
The current path didnt match any of these Error when adding a link to a button
一直在尝试添加一个 link,尽管模板可以正常工作,但它一直向我发送错误消息。
Views.py
def store(request):
context = {}
return render(request, 'store/store.html', context)
def cart(request):
context = {}
return render(request, 'store/cart.html', context)
def checkout(request):
context = {}
return render(request, 'store/checkout.html', context)
Urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('store.urls'))
]
main.html
<a class="nav-link" href="{$ url 'cart' %}">Store <span class="sr-only">
(current)</span></a>
<a class="nav-link" href="{$ url 'store' %}">Store <span class="sr-only">
(current)</span></a>
<a class="nav-link" href="{$ url 'checkout' %}">Store <span class="sr-only">
(current)</span></a>
Store.urls
from django.urls import path
from . import views
urlpatterns = [
path('', views.store, name='store'),
path('cart/', views.cart, name='cart'),
path('checkout/', views.checkout, name='checkout'),
]
url 路由向我发送错误,但我可以通过 127.0.0.1:8000/cart 和 127.0.0.1:8000/ works for store 和 127.0.0.1:8000/checkout works 访问模板结帐。但我无法通过 links
访问
尝试更正您 main.html 的 href 中的一些拼写错误:% 而不是 $.
应该是:
<a class="nav-link" href="{% url 'cart' %}">Store <span class="sr-only">
(current)</span></a>
<a class="nav-link" href="{% url 'store' %}">Store <span class="sr-only">
(current)</span></a>
<a class="nav-link" href="{% url 'checkout' %}">Store <span class="sr-only">
(current)</span></a>
一直在尝试添加一个 link,尽管模板可以正常工作,但它一直向我发送错误消息。
Views.py
def store(request):
context = {}
return render(request, 'store/store.html', context)
def cart(request):
context = {}
return render(request, 'store/cart.html', context)
def checkout(request):
context = {}
return render(request, 'store/checkout.html', context)
Urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('store.urls'))
]
main.html
<a class="nav-link" href="{$ url 'cart' %}">Store <span class="sr-only">
(current)</span></a>
<a class="nav-link" href="{$ url 'store' %}">Store <span class="sr-only">
(current)</span></a>
<a class="nav-link" href="{$ url 'checkout' %}">Store <span class="sr-only">
(current)</span></a>
Store.urls
from django.urls import path
from . import views
urlpatterns = [
path('', views.store, name='store'),
path('cart/', views.cart, name='cart'),
path('checkout/', views.checkout, name='checkout'),
]
url 路由向我发送错误,但我可以通过 127.0.0.1:8000/cart 和 127.0.0.1:8000/ works for store 和 127.0.0.1:8000/checkout works 访问模板结帐。但我无法通过 links
访问尝试更正您 main.html 的 href 中的一些拼写错误:% 而不是 $.
应该是:
<a class="nav-link" href="{% url 'cart' %}">Store <span class="sr-only">
(current)</span></a>
<a class="nav-link" href="{% url 'store' %}">Store <span class="sr-only">
(current)</span></a>
<a class="nav-link" href="{% url 'checkout' %}">Store <span class="sr-only">
(current)</span></a>