1、配置URLConf
    MyDjango > news > urls.py

    1. path('', views.index),
    2. path('details/<int:question:id>', views.details)

    2、自定义视图
    MyDjango > news > views.py

    1. from django.shortcuts import render
    2. from django.http import HttpResponse
    3. def index(request):
    4. question_list = [
    5. {'id': 1, 'question_text': 'This is question 1'},
    6. {'id': 2, 'question_text': 'This is question 2'},
    7. {'id': 3, 'question_text': 'This is question 3'},
    8. ]
    9. context = {'question_list': question_list}
    10. template_name = 'news/details.html'
    11. return render(request, template_name, context)
    12. def details(request, question_id):
    13. return HttpResponse('Hello %s' %question_id)

    3、自定义模型
    MyDjango > news > templates > news > details.html

    1. {% if question_list %}
    2. <ul>
    3. {% for question in question_list %}
    4. <li><a href="{% url 'news:details' question.id %}">{{ question.question_text }}</a></li>
    5. {% endfor %}
    6. </ul>
    7. {% else %}
    8. <p>No polls are available.</p>
    9. {% endif %}

    4、浏览器请求
    http://127.0.0.1:8080/news/
    image.png