我是Django的新手,我只是试图将参数传递给Django通用基本View,并且它没有显示在终端中,因为我正在打印传递的参数。
views.py
from django.views.generic import View
class CartView(View):
def get(self, request, *args, **kwargs):
item = request.GET.get('item')
qty = request.GET.get('qty')
print item, qty
return HttpResponseRedirect('/')
urls.py:
urlpatterns = [
url(r'^home/$', 'newsletter.views.home', name='home'),
url(r'^contact/$', 'newsletter.views.contact', name='contact'),
url(r'^about/$', 'dressika.views.about', name='about'),
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('registration.backends.default.urls')),
url(r'^', include('products.urls')),
url(r'^categories/', include('products.urls_categories')),
url(r'^cart/', CartView.as_view(), name='cart'),
当我在"localhost:8000/cart/?item=2&qty=5"
这样的浏览器中添加一些数据时,根据上面的代码,它没有显示终端中的参数。只需键入"localhost:8000/cart/"
,它就会将我重定向到主页。但有论据显示404.
答案 0 :(得分:0)
听起来您可能需要修复urls.py路由中的条目到视图。你也可以发布你的urls.py吗?