0

我正在向用户发送电子邮件。我有一个工作链接让用户将布尔设置为“真”。虽然,我无法获得正确的 URL 将其设置为 False。在views.py中:

def confirm(request, itemnum):
    item = get_object_or_404(PurchaseOrder, item_number = itemnum)
    item.confirmed = True
    item.save()
    return HttpResponse('Item number %s  changed to true' % itemnum )

def deny(request, itemnum):
    item = get_object_or_404 (PurchaseOrder, item_number = itemnum)
    item.confirmed = False
    item.save()
    return HttpResponse('Item number %s changed to false' %itemnum)

在 urls.py 中:

urlpatterns = patterns('',

    url(r'^(?P<itemnum>\d+)/$', views.confirm, name = 'confirm-page'), #This it to set the bool as true. I just need a url to set it as false that uses a itemnum, but somehow adds a keyword maybe such as false/56/
 )

我需要设置一个 URL,让用户使用每个项目的唯一主键将其更改为 false。但我该怎么做呢?

4

1 回答 1

2

你可以urlpatterns这样设置:

urlpatterns = patterns('',
    url(r'^confirm/(?P<itemnum>\d+)/$', 'yourapp.views.confirm', name='confirm-page'),
    url(r'^deny/(?P<itemnum>\d+)/$', 'yourapp.views.deny', name='deny-page'),
)

因此,如果用户访问http://yourdomain.com/confirm/3/,那么它将confirm以 = 3 进行查看itemnum。同样,如果用户访问http://yourdomain.com/deny/5/,它将导致以deny= itemnum5进行查看

于 2013-07-30T13:45:47.643 回答