- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在研究 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/
我有以下代码,如您所见, View 中有一个C_account()函数,但是我仍然在 **Exception Type: ViewDoesNotExist at /create_account/ Ex
我遇到了一个错误: Caught ViewDoesNotExist while rendering: Tried my_view_two in module yourmodule.views. Err
我正在尝试解决一个问题:Django 告诉我我的 View 不存在,但我创建了一个应该以相同名称加载的 View 。我有以下错误: ViewDoesNotExist at / Could not im
当我添加一个表单来添加电话号码时,一切正常。 但是,当我为 full_name 添加字段时,出现此错误: ViewDoesNotExist at /phone/ Could not import ac
我正在研究 Practical Django Proects,但遇到了困难。我收到错误: Caught ViewDoesNotExist while rendering: Tried tagged_o
我在处理具有 FormView 的 View 时遇到问题。我正在尝试使用 s3direct插件。 该错误指定 '' is not a callable or a dot-notation path .
我是一名优秀的程序员,十分优秀!