gpt4 book ai didi

python - get_absolute_url 问题。错误捕获 ViewDoesNotExist

转载 作者:行者123 更新时间:2023-11-29 05:38:04 25 4
gpt4 key购买 nike

我正在研究 Practical Django Proects,但遇到了困难。我收到错误:

Caught ViewDoesNotExist while rendering: Tried tagged_objects_list in module tagging.views. Error was: 'module' object has no attribute 'tagged_objects_list'.

如果我将 entry_archive.html 中的所有“object”更改为“entry”(object.get_absolute_url 除外),错误就会消失。然后我点击“Read Full Entry”,它重定向到/weblog/而不是绝对 URL。奇怪的是,如果我将所有“对象”引用保留为“对象”并将行更改为 entry.get_absolute_url,则错误消失但上面的/weblog/重定向仍然发生。

/cms/urls.py:

url(r'^weblog/', include('coltrane.urls.entries')),

/coltrane/urls/entries.py

from django.conf.urls.defaults import *
from coltrane.models import Entry

# define entry_info_dict used for generic view
entry_info_dict = {
'queryset': Entry.objects.all(),
'date_field': 'pub_date',
}

# Generic Views URL Patterns
urlpatterns = patterns('django.views.generic.date_based',
# Weblog index - Generic View
url(r'^$', 'archive_index', entry_info_dict, 'coltrane_entry_archive_index'),
# Archive year - Generic View
url(r'^(?P<year>\d{4})/$', 'archive_year', entry_info_dict, 'coltrane_entry_archive_year'),
# Archive month - Generic View
url(r'^(?P<year>\d{4})/(?P<month>\w{3})/$', 'archive_month', entry_info_dict, 'coltrane_entry_archive_month'),
# Archive day - Generic View
url(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/$', 'archive_day', entry_info_dict, 'coltrane_entry_archive_day'),
# Weblog detail - Generic View
url(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$', 'object_detail', entry_info_dict, 'coltrane_entry_detail'),
)

entry_archive.html 内容:

<div id="contentarea">
{% block content %}
{% for object in latest %}
<h2>{{ object.title }}</h2>
<p>Published on {{ object.pub_date|date:"F j, Y" }}</p>
{% if object.excerpt_html %}
{{ object.excerpt_html|safe }}
{% else %}
{{ object.body_html|truncatewords_html:"50"|safe }}
{% endif %}
<p><a href="{{ object.get_absolute_url }}">Read full entry</a></p>
<br>
{% endfor %}
{% endblock %}
</div>

models.py 中 Entry 的绝对 url:

def get_absolute_url(self):
return ('coltrane_entry_detail', (), { 'year': self.pub_date.strftime("%Y"),
'month': self.pub_date.strftime("%b").lower(),
'day': self.pub_date.strftime("%d"),
'slug': self.slug })
get_absolute_url = models.permalink(get_absolute_url)

我在搜索时看到过类似的问题,但大多数问题似乎都可以通过将 weblog 的 url 设置为 weblog/$' 来解决,而我的情况并非如此。只是为了确定我已经尝试将 coltrane/urls/entries.py 中的第一个 url 更改为 url(r'^' 而不是 url(r'^$' 并且我仍然遇到同样的问题。

谢谢

最佳答案

您不应该在 models.permalink 中调用 reverse() —— 只需返回元组即可。

return reverse(...) 应该是 return (...)

关于python - get_absolute_url 问题。错误捕获 ViewDoesNotExist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9057880/

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