我不知道我的错误是什么意思:NoReverseMatch在/ sssss / Reverse for''with arguments'(9,19)'和关键字参数'{}'找不到

时间:2022-03-05 23:23:48

I'm using django-favorites for follow/unfollow strategy. https://bitbucket.org/last_partizan/django-favorites/overview
Problem is this might be wrote for django lower than 1.7 maybe and I'm using django 1.8. I fixed most of errors but now I get NoReverseMatch at /sssss/

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

Reverse for '' with arguments '(9, 19)' and keyword arguments '{}' not found. 0 pattern(s) tried: []

反向''带参数'(9,19)'和关键字参数'{}'未找到。尝试过0种模式:[]

I have no idea what this is or how to fix this. It says it's coming from fav_item.html,which is part of app. from this line {% url ajax_fav ctype.id item.id %} Here is the rest of the code

我不知道这是什么或如何解决这个问题。它说它来自fav_item.html,它是app的一部分。从这一行{%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>

I'm trying to use it on my category model

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

# 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

Is this ajax problem?really what does the error mean...

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

Really hope this gets fixed

真的希望这个得到修复

Edit:

  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')

1 个解决方案

#1


0  

If you want to use this app, you will need to copy over that template into your own app and change that line to use quotes around the view name:

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

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

#1


0  

If you want to use this app, you will need to copy over that template into your own app and change that line to use quotes around the view name:

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

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