I have no idea what my error means: NoReverseMatch at /sssss/ Reverse for '' with arguments '(9, 19)' and keyword arguments '{}' not found

喜你入骨 提交于 2019-12-25 14:27:12

问题


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/

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

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

<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...

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:


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 %}


来源:https://stackoverflow.com/questions/34760346/i-have-no-idea-what-my-error-means-noreversematch-at-sssss-reverse-for-wit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!