尝试安装django-likes时出现以下错误
NoReverseMatch at / post / 25 /
反向''有参数'(' posts-post',25,1)'和关键字参数' {}'未找到。尝试了0种模式:[]
异常位置:/Users/Pete/.virtualenvs/innerlocal-mvp/lib/python2.7/site-packages/django/core/urlresolvers.py in _reverse_with_prefix,第463行
我不知道从哪里开始这个错误,我已经做了很多搜索,但没有任何结果。
我认为这是指:
def single_post(request, id):
post = get_object_or_404(Post, id=id)
...
return render(request, 'posts/single_post.html', locals())
在html中{%like post%}。
并从生成的html中突出显示该行:
<a class="liker" href="{% url like content_type content_obj.id 1 %}" rel="nofollow">{% trans "I Like" %}</a>
我使用的是Django 1.7,如果这是一个问题,我不会感到惊讶。
非常感谢任何帮助!!
根据要求提供额外设置:
urls.py行(首先是app,第二行,django-like url:
url(r'^', include('posts.urls')),
(r'^likes/', include('likes.urls')),
和帖子应用的urls.py:
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView
from views import PostDelete
urlpatterns = patterns('posts.views',
# (r'^', 'home'),
url(r'^$', 'all_posts', name='home'),
url(r'^post/(?P<id>\w+)/$', 'single_post', name='single_post'),
url(r'^new-post/$', 'new_post', name='new_post'),
url(r'^search/$', 'search', name='search'),
url(r'^delete/(?P<pk>\d+)/$', PostDelete.as_view(),
name='entry_delete'),
)
已安装的应用:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'django.contrib.sites',
....
'secretballot',
'likes',
)
中间件类:
MIDDLEWARE_CLASSES = (
'django.middleware.gzip.GZipMiddleware',
'pipeline.middleware.MinifyHTMLMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'secretballot.middleware.SecretBallotIpMiddleware',
'secretballot.middleware.SecretBallotIpUseragentMiddleware',
'likes.middleware.SecretBallotUserIpUseragentMiddleware',
)
模板上下文处理器:
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.request",
"allauth.account.context_processors.account",
"allauth.socialaccount.context_processors.socialaccount",
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.static",
"django.core.context_processors.media",
"django.contrib.messages.context_processors.messages",
)
答案 0 :(得分:0)
原来应用程序代码需要更改:
在likes.html中
这
<a class="liker" href="{% url like content_type content_obj.id 1 %}" rel="nofollow">{% trans "I Like" %}</a>
到
<a class="liker" href="{% url 'like' content_type content_obj.id 1 %}" rel="nofollow">{% trans "I Like" %}</a>
ie - 'like'周围的引号