Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
NoReverseMatch实现django-likes_Django - Fatal编程技术网

NoReverseMatch实现django-likes

NoReverseMatch实现django-likes,django,Django,尝试安装django时出现以下错误 NoReverseMatch at/post/25/ 相反,找不到带有post、25、1和关键字参数“{}”的参数post。已尝试0个模式:[] 异常位置:/Users/Pete/.virtualenvs/innerlocal mvp/lib/python2.7/site-packages/django/core/urlresolvers.py in_reverse_,带_前缀,第463行 我甚至不知道从哪里开始这个错误,我做了很多搜索,但什么都没有出现 我认

尝试安装django时出现以下错误

NoReverseMatch at/post/25/

相反,找不到带有post、25、1和关键字参数“{}”的参数post。已尝试0个模式:[]

异常位置:/Users/Pete/.virtualenvs/innerlocal mvp/lib/python2.7/site-packages/django/core/urlresolvers.py in_reverse_,带_前缀,第463行

我甚至不知道从哪里开始这个错误,我做了很多搜索,但什么都没有出现

我认为这是指:

def single_post(request, id):
    post = get_object_or_404(Post, id=id)
    ...

    return render(request, 'posts/single_post.html', locals())
在html中使用{%likes post%}

从生成的html中突出显示这一行:

<a class="liker" href="{% url like content_type content_obj.id 1 %}" rel="nofollow">{% trans "I Like" %}</a>
以及posts应用程序的url.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'),
)
中间件类:

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",
)

结果表明,应用程序代码需要更改:

在likes.html中


ie-围绕“like”的引号

您是如何将django likes集成到您的项目中的?将已安装的应用程序、中间件类、模板上下文处理器设置添加到问题中。另外添加URL.py,其中包括django-likes URL。您的问题在于URL,能否显示您的URL.py?感谢您的回复-我已经添加了额外的信息,让我知道我还可以提供什么!
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",
)
<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>