【问题标题】:I have no idea what my error means: NoReverseMatch at /sssss/ Reverse for '' with arguments '(9, 19)' and keyword arguments '{}' not found我不知道我的错误是什么意思: NoReverseMatch at /sssss/ Reverse for '' with arguments '(9, 19)' and keyword arguments '{}' not found
【发布时间】:2016-04-18 01:16:12
【问题描述】:

我正在使用 django-favorites 进行关注/取消关注策略。 https://bitbucket.org/last_partizan/django-favorites/overview
问题是这可能是为低于 1.7 的 django 编写的,而我使用的是 django 1.8。 我修复了大部分错误,但现在我在 /sssss/ 得到 NoReverseMatch

对于带有参数 '(9, 19)' 和关键字参数 '{}' 的 '' 不反向 成立。尝试了 0 个模式:[]

我不知道这是什么或如何解决这个问题。 它说它来自 fav_item.html,它是应用程序的一部分。 从这条线{% url ajax_fav ctype.id item.id %} 这是剩下的代码

<a href="#" class="favIt" id="FavIt_{{ item.id }}" data-action-url="{% url ajax_fav ctype.id item.id %}">{{ message }}</a> 
<span class="favsCounter" id="FavCounter_{{ item.id }}">{{ counter }}</span>

我正在尝试在我的类别模型上使用它

# Create your models here.
class Category(models.Model): 
    name = models.CharField(max_length=128, unique=True)
    slug = models.CharField(max_length=100, unique=True)
    author = models.OneToOneField(settings.AUTH_USER_MODEL, unique=True)
    def save(self, *args, **kwargs):
        self.slug = uuslug(self.name,instance=self, max_length=100)
        super(Category, self).save(*args, **kwargs)

    def __unicode__(self): 
        return self.name

这是ajax问题吗?真的是什么错误意思...

真的希望能解决这个问题

编辑:

  from django.conf.urls import *

    urlpatterns = patterns('',
        url(r'^fav/(?P<ctype_id>\d+)/(?P<obj_id>\d+)/$', 'favorites

.views.ajax_fav', name="ajax_fav"),        
)

views.py

#!/usr/bin/env python
# encoding: utf-8
from django.contrib.contenttypes.models import ContentType
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
import json as simplejson
from favorites import settings as fav_settings
from favorites.models import Favorite
from favorites.utils import build_message

def ajax_login_required(view_func):
    def wrap(request, *args, **kwargs):
        if request.user.is_authenticated():
            return view_func(request, *args, **kwargs)
        json = simplejson.dumps({'not_authenticated': True})
        return HttpResponse(json, mimetype='application/json', status=401)
    wrap.__doc__ = view_func.__doc__
    wrap.__dict__ = view_func.__dict__
    return wrap

@ajax_login_required
def ajax_fav(request, ctype_id, obj_id):
    """

    """
    ctype = get_object_or_404(ContentType, pk=ctype_id)
    item = ctype.get_object_for_this_type(pk=obj_id)    
    if Favorite.objects.filter(user=request.user, content_type=ctype, object_id=obj_id):
        fav = Favorite.objects.get(user=request.user, content_type=ctype, object_id=obj_id)
        fav.delete()
        count = Favorite.objects.favorites_for_object(item).count()
        data_dict = {'id': 0, 'message': fav_settings.FAV_ADD, 'counter': build_message(count), }
    else:        
        fav = Favorite.objects.create_favorite(item, request.user)
        count = Favorite.objects.favorites_for_object(item).count()
        data_dict = {'id': fav.id, 'message': fav_settings.FAV_REMOVE, 'counter': build_message(count), }
    return HttpResponse(simplejson.dumps(data_dict), mimetype='application/javascript')

【问题讨论】:

  • 在此之前:我遇到了这个问题stackoverflow.com/questions/34758162/…
  • @Baterson 嘿伙计,我发现了缩略图问题,记住我/
  • @Sayse 当然,它来自 django.conf.urls import * urlpatterns = patterns('', url(r'^fav/(?P\d+)/(?P\d+)/$', 'favorites.views.ajax_fav', name="ajax_fav"), )
  • 请使用edit button添加新信息,您可能还需要包含视图
  • @Sayse,顺便说一句,我没有写这个,它仍然是应用程序 django-favorites 的一部分

标签: python ajax django django-urls


【解决方案1】:

如果您想使用此应用程序,您需要将该模板复制到您自己的应用程序中,并将该行更改为在视图名称周围使用引号:

{% url "ajax_fav" ctype.id item.id %}

【讨论】:

  • 哦,我要放弃了,把最喜欢的 html 复制到我的 html 中?
  • 哇,谢谢,我不知道为什么,但把报价放在那里是可行的。我需要将模板复制到我的应用程序是什么意思?你的意思是我需要把 {{ message }} {{ counter }} 到我的“喜欢”所在的html文件用过吗?
  • 至少我现在可以吃,,,把这个放在一边
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-23
  • 1970-01-01
  • 2022-06-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多