gpt4 book ai didi

django-templates - 渲染 : Reverse for '' with arguments '(1,)' and keyword arguments '{}' not found 时捕获 NoReverseMatch

转载 作者:行者123 更新时间:2023-12-04 07:44:12 25 4
gpt4 key购买 nike

我的观点 :

def display(request):
feed = SoukFeedMaster.objects.filter(person = request.user)
return render(request, 'soukfeed/display.html', {'feed' : feed ,})

我的模板:
{% extends "base.html" %}

{% block content %}
{% for x in feed %}
{% load url from future %}
<a href="{% url x.content.url_internal_django_link x.content.id %}"> {{x.content.content}} </a>
<br/>
{% endfor %}

{% endblock %}

追溯 :
Environment:


Request Method: GET
Request URL: http://localhost:8000/soukfeed/

Django Version: 1.3
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.comments',
'ec.kiosk',
'ec.chakra',
'ec.ajax',
'ec.broadcast',
'ec.connect',
'ec.seek_solutions',
'ec.feed',
'ec.ec_model',
'ec.info',
'ec.souk_info',
'ec.ec_central',
'ec.domains',
'ec.souk',
'ec.souk_feed',
'ec.meta',
'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')


Template error:
In template /volumes/disk2/workspace/templates/ec/soukfeed/display.html, error at line 1
Caught NoReverseMatch while rendering: Reverse for '' with arguments '(1,)' and keyword arguments '{}' not found.
1 : {% extends "base.html" %}

{% block content %}
{% for x in feed %}
{% load url from future %}
<a href="{% url x.content.url_internal_django_link x.content.id %}"> {{ x.content.content }} </a>
<br/>
{% endfor %}

{% endblock %}


Traceback:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/Volumes/Disk2/workspace/ec/ec/souk_feed/views.py" in display
18. return render(request, 'soukfeed/display.html', {'feed' : feed ,})
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/shortcuts/__init__.py" in render
44. return HttpResponse(loader.render_to_string(*args, **kwargs),
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
188. return t.render(context_instance)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py" in render
123. return self._render(context)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py" in _render
117. return self.nodelist.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/loader_tags.py" in render
127. return compiled_parent._render(context)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py" in _render
117. return self.nodelist.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/loader_tags.py" in render
64. result = block.nodelist.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/defaulttags.py" in render
227. nodelist.append(node.render(context))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/defaulttags.py" in render
450. raise e

Exception Type: TemplateSyntaxError at /soukfeed/
Exception Value: Caught NoReverseMatch while rendering: Reverse for '' with arguments '(1,)' and keyword arguments '{}' not found.

最佳答案

我的应用程序也遇到了同样的问题。以下为我解决了它:

因为您使用的是 {% url %}标记生成 View 的链接,您需要将应用程序的 URL 添加到项目的根 URLConf 模块(通过 include() 调用)。如果您使用 {% url %}带有您尚未在项目中设置的 URL 名称的标签,它将无法找到正确的 URL,并且只会返回一个空字符串而不是 URL。

所以基本上问题是你要查找的url必须在你项目的urls.py中,否则django找不到跟踪它。

关于django-templates - 渲染 : Reverse for '' with arguments '(1,)' and keyword arguments '{}' not found 时捕获 NoReverseMatch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5643697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com