反向查找“ add_items”,未找到任何参数。尝试了1个模式:['add_items \\ /(?P <披萨名称> [^ /] +)\\ / $']

时间:2018-09-12 19:00:38

标签: python django

如何解决此错误,我也想使用此网址发送多个变量

Reverse for 'add_items' with arguments '('1 Topping',)' not found. 1 pattern(s) tried: ['add_items\\/(?P<pizza_name>[-a-zA-Z0-9_]+)\\/$']

index.html

<table>
        {% for pizza in r_pizzas %}

        <tr><a href="{% url 'add_items' pizza.pizza_type %}">{{pizza.pizza_type}}  , {{pizza.small}}   , {{pizza.large}}</a> </tr><br><hr>

        {% endfor %}
      </table>

urls.py

from django.urls import path
from . import views

urlpatterns = [
path("", views.index, name="index"),
path("login" , views.login_view , name="login"),
path("logout" , views.logout_view , name="logout"),
path("register" , views.register , name="register"),
path("registration_successful" , views.registered , name="registered"),
path("add_items/<pizza_name>/" , views.add_items , name="add_items")


]

views.py

def add_items(request , pizza_name ):
item = pizza_name

相关模型

class Sicilian_Pizza(models.Model):
    pizza_type = models.CharField(max_length=64 ,  default=None)
    small = models.DecimalField(max_digits=5, decimal_places=2 , default=None)
    large = models.DecimalField(max_digits=5, decimal_places=2 , default=None)  

0 个答案:

没有答案