发生了什么事。我仍然无法显示标题列表。我在哪里弄错了?
views.py
def dashboard(request):
bookmarks = Text_field.objects.order_by('created')
return render(request, 'Site/dashboard.html', {'bookmarks': bookmarks})
def about_me(request, pk):
about = get_object_or_404(Text_field, pk=pk)
return render(request, 'Site/about_me.html', {'about': about})
dashboard.html
{% extends "Site/base.html" %}
{% load static %}
{% block content %}
{% for bookmark in bookmarks %}
<div>
<p>Stworzono dn. {{ bookmark.created }}</p>
<h1><a href="{% url "about_me" pk=about.pk %}">{{ bookmark.title }}</a></h1>
<p>{{ bookmark.text|linebreaksbr }}</p>
</div>
{% endfor %}
{% endblock %}
urls.py
path('', views.dashboard, name='dashboard'),
path('about/<int:pk>/', views.about_me, name='about_me'),
答案 0 :(得分:0)
在您的comment中,您说您在app_name
中定义了一个urls.py
,您需要在您的app_name
名称中包括该{% url ... %}
:
{% url 'Site:about_me' pk=bookmark.pk %}