2011-04-13 58 views
8

我的觀點:陷入NoReverseMatch而呈現:反轉爲 '' 與參數 '(1)' 和關鍵字參數 '{}' 未找到

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

可能是什麼問題? – user677990 2011-04-13 02:36:54

+1

編輯你的帖子,包括你的urls.py和你的模型SoukFeedMaster – DTing 2011-04-13 03:57:16

回答

1

它真的不夠信息。但問題就在這裏:

{% url x.content.url_internal_django_link x.content.id %} 

可能是你需要的是:

{% extends "base.html" %} 

{% block content %}  
{% for x in feed %} 
    <a href="{{ x.content.get_absolute_url }}"> {{x.content.content}} </a> 
    <br/> 
{% endfor %} 

{% endblock %} 

但我不知道 - 它從你的模型代碼取決於你的一般邏輯

0

異常值:在呈現時捕獲NoReverseMatch :未找到參數'(1,)'和關鍵字參數 '{'''與 ''相反的''。

它看起來像你的x.content.url_internal_django_link返回一個空字符串。

檢查你的數據庫或臨時更改{% url %}標籤:

{{ x.content.url_internal_django_link }} 

,看看有什麼是存儲,爲什麼你是從數據庫得到空字符串。

0

我已經得到了同樣的異常輸出說不能「(93L)」和關鍵字參數沒有找到。

檢查urls.py,在那裏你可以看到網址不提供there.So提供的網址,然後youre不去這個錯誤。

7

剛剛對我的應用程序有同樣的問題。以下解決方案適用於我:

由於您使用{% url %}標記來生成視圖鏈接,因此需要將應用程序的URL添加到項目的根URLConf模塊(通過include()調用)。如果您將{% url %}標記與您尚未在項目中設置的URL名稱一起使用,則它將無法找到正確的URL並僅返回空字符串而不是URL。

所以基本上問題是,你正在尋找了URL必須在項目的urls.py,否則Django的不能找到和跟蹤它。

0

另一種可能性是URL的正則表達式字符串與您的請求不匹配。用戶名用戶名

相關問題