社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  问与答

Reverse for 'depotapp.views.view_product item.id' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

tmlvampire-weibo • 9 年前 • 6373 次点击  

我使用了Django-groundwork这个第三方app

django 1.6 python 2.7

输入http://localhost:8000/depotapp/product/list/后出现错误 In template /home/tml/PycharmProjects/depot/templates/depotapp/list_product.html, error at line 22

Reverse for 'depotapp.views.view_product item.id' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

depot/tempates/depot/list_product.html

{% extends "base.html" %} {%block title%}产品清单{% endblock %} {% block content %} <div class="container"> <div class="container">

<h2>产品清单</h2>

</div> </div> {% for item in list_items.object_list %} <div class="row" style="padding-top:2px"> <div class="span3 media-grid"> <a href="#"> <img class="thumbnail" src="{{item.image_url}}" alt=""> </a> </div> <div class="span-two-thirds"> <h4>{{item.title}}</h4> {{item.description}} </div> <div class="span2" style="align:righ"> <p><a class="btn primary" href="{% url 'depotapp.views.view_product item.id' %}">查看</a> </p> <p><a class="btn success" href="{% url 'depotapp.views.edit_product item.id' %}">编辑</a> </p> <p><a class="btn danger" href="#">删除</a></p>

    </div>
  </div>

{% endfor %} {% if list_items.has_previous %} <a href="?page={{ list_items.previous_page_number }}">上一页</a> {% endif %} <span class="current"> 第{{ list_items.number }}页,共{{ list_items.paginator.num_pages }}页 </span> {% if list_items.has_next %} <a href="?page={{ list_items.next_page_number }}">下一页</a> {% endif %} <p> <a href="{% url "depotapp.views.create_product" %}">新增产品</a> </p>

{% endblock %}

depot/depot/urls.py

from django.conf.urls import patterns, include, url from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.contrib import admin admin.autodiscover()

urlpatterns = patterns('', # Examples: # url(r'^$', 'depot.views.home', name='home'), # url(r'^blog/', include('blog.urls')),

url(r'^admin/', include(admin.site.urls)),

) urlpatterns += patterns('', url(r'^depotapp/', include('depotapp.urls')), ) urlpatterns += staticfiles_urlpatterns()

depot/depotapp/urls.py

from django.conf.urls import from models import from views import *

urlpatterns = patterns('',

(r'product/create/$', create_product),
(r'product/list/$', list_product ),
(r'product/edit/(?P<id>[^/]+)/$', edit_product),
(r'product/view/(?P<id>[^/]+)/$', view_product),

)

depot/depotapp/views.py

from django import forms from django.template import RequestContext from django.http import HttpResponse, HttpResponseRedirect from django.template.loader import get_template from django.core.paginator import Paginator from django.core.urlresolvers import reverse

from models import * from forms import *

def create_product(request): form = ProductForm(request.POST or None) if form.is_valid(): form.save() form = ProductForm()

t = get_template('depotapp/create_product.html')
c = RequestContext(request,locals())
return HttpResponse(t.render(c))

def list_product(request):

list_items = Product.objects.all()
paginator = Paginator(list_items ,10)


try:
    page = int(request.GET.get('page', '1'))
except ValueError:
    page = 1

try:
    list_items = paginator.page(page)
except :
    list_items = paginator.page(paginator.num_pages)

t = get_template('depotapp/list_product.html')
c = RequestContext(request,locals())
return HttpResponse(t.render(c))

def view_product(request, id): product_instance = Product.objects.get(id = id)

t=get_template('depotapp/view_product.html')
c=RequestContext(request,locals())
return HttpResponse(t.render(c))

def edit_product(request, id):

product_instance = Product.objects.get(id=id)

form = ProductForm(request.POST or None, instance = product_instance)

if form.is_valid():
    form.save()

t=get_template('depotapp/edit_product.html')
c=RequestContext(request,locals())
return HttpResponse(t.render(c))
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/1019
 
6373 次点击  
文章 [ 2 ]  |  最新文章 9 年前
tmlvampire-weibo
Reply   •   1 楼
tmlvampire-weibo    9 年前

知道错在那里了。。 url'depotapp.views.view_product item.id'改成 url'depotapp.views.view_product' item.id就对了。。。。

tmlvampire-weibo
Reply   •   2 楼
tmlvampire-weibo    9 年前

http://localhost:8000/depotapp/product/create/ 输入这个时能出来页面的