Hello!

There is:

url.py

urlpatterns = [ path(r'topics/<topic_id>', views.topic, name='topic') ] 

view.py

 def topic(request, topic_id): """ Выводит одну тему и все ее записи """ topic = Topic.objects.get(id=topic_id) entries = topic.entry_set.order_by('-date_added') context = {'topic': topic, 'entries': entries} return render(request=request, template_name='learning_logs/topic.html', context=context) 

Can't figure out how the path sends topic_id to view.topic ?

    1 answer 1

    path does not send anything. This function only returns URLResolver at the stage of loading the project code at server startup. urlpatterns , when Django accepts an http request, WSGIHandler through the list of urlpatterns , comparing the request URL and the pattern of each URLResolver in turn. When the most suitable is found, it extracts the parameters from the request, according to the pattern, and calls the corresponding view with these parameters.

    • one
      It seems I realized. What is in the angle brackets is the second parameter topic_id. - Albert Alexandrov
    • one
      Yeah, that's him. - Sergey Gornostaev