我已经在这里攀登了很多游戏,但没有找到解决问题的确切答案 错误指向{%url“entry_detail”slug = object.slug%} ... 这是home.html
{% extends 'base.html' %}
{% block blog_entries %}
<a href="{% url "entry_detail" slug=object.slug %}">
<figure>
<img src="{{ MEDIA_URL }}{{ object.image }}" />
<svg viewBox="0 0 180 320" preserveAspectRatio="none"><path d="M 0 0 L 0 182 L 90 126.5 L 180 182 L 180 0 L 0 0 z "/></svg>
<figcaption>
<h2>{{ object.title }}</h2>
<button>Read</button>
</figcaption>
</figure>
</a>
{% endblock %}
views.py
from django.views import generic
from django.views.generic import TemplateView
from blog import models
class BlogIndex(generic.ListView):
queryset = models.Entry.objects.published()
template_name = "home.html"
class BlogDetail(generic.DetailView):
model = models.Entry
template_name = "post.html"
urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from blog import views
from django.conf import settings
urlpatterns = patterns('',
url(r'^$', views.BlogIndex.as_view(), name="index"),
url(r'^admin/', include(admin.site.urls)),
url(r'^entry/(?P<slug>/S+)$', views.BlogDetail.as_view(), name="entry_detail"),
)
models.py
@models.permalink
def get_absolute_url(self):
return reverse("entry_detail", kwargs={"slug": self.slug})
答案 0 :(得分:0)
尝试...将slug作为模板中的位置参数传递。
{%url&#39; entry_detail&#39; object.slug%}