implement issues index and detail view, using templates

This commit is contained in:
Lexi / Zoe 2019-05-27 15:18:57 +02:00
parent 43c127d744
commit a14ab33927
Signed by: binaryDiv
GPG Key ID: F8D4956E224DA232
4 changed files with 34 additions and 4 deletions

View File

@ -0,0 +1,6 @@
<h2>#{{ issue.id }}: {{ issue.title }}</h2>
<p>
<b>Project:</b> {{ issue.project }}<br/>
<b>Created:</b> {{ issue.create_date }}
</p>
<p>{{ issue.text }}</p>

View File

@ -0,0 +1,11 @@
{% if issue_list %}
<ul>
{% for issue in issue_list %}
<li>
<a href="{% url 'issues:detail' issue.id %}">{{ issue.title }}</a>
</li>
{% endfor %}
</ul>
{% else %}
<p>No issues.</p>
{% endif %}

View File

@ -2,6 +2,8 @@ from django.urls import path
from . import views
app_name = 'issues'
urlpatterns = [
path('', views.index, name='index')
path('', views.index, name='index'),
path('<int:issue_id>/', views.detail, name='detail'),
]

View File

@ -1,6 +1,17 @@
# from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render
from .models import Issue
def index(request):
return HttpResponse('Hello Tofu.')
issue_list = Issue.objects.order_by('create_date')
return render(request, 'issues/index.html', {
'issue_list': issue_list,
})
def detail(request, issue_id):
issue = get_object_or_404(Issue, pk=issue_id)
return render(request, 'issues/detail.html', {
'issue': issue,
})