Django / Python does not follow links to html pages. How do I fix this?

I wanted to create a simple bulletin board (I just started learning Django). One of the tasks was to create several html pages and one basic one, which contains links to them (and in the hint to the solution it was said that you need to edit the html document for this) Project structure

The list page loads perfectly (advertisement_list.html), it was expected, as in the example, that when you click on the link in advertisement_list.html, the transition will be made to page advertisement1.html but this does not happen((( And I tried everything: specify in href and "/advertisement1.html " and the full path, but nothing helps. Below is a snippet of the html code advertisement_list.html

<html>
<h2><a href="advertisement1.html"> Advertisement 1 </a></h2>
</html>

When you click on the link, a 404 code pops up enter a description of the image here

Can you please tell me how to fix it (I sit for 2 days and tried all the options. It only works if you create another app inside the board via startapp and make it like this same as advertisements)

Just in case, the code urls.py and views.py from advertisements

Advertisements/urls.py

from django.urls import path
from .import views

urlpatterns = [
    path('', views.advertisement_list, name='advertisement_list'),
]

Advertisements/views.py

from django.shortcuts import render

# Create your views here.
def advertisement_list(request, *args, **kwargs):
    return render(request, 'advertisements/advertisement_list.html', {})

Board/urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path("admin/", admin.site.urls),
    path('advertisements/', include('advertisements.urls')),

]
Author: Dmitriy, 2020-12-02

1 answers

You need to write a controller (in django terminology, this is View), which, by analogy with a list, will render the template of a specific declaration. Pass to this View the id or other attribute of the ad, by which you will select it from the database.

Then put your ad in the context of the template and insert the data of your specific ad in the template in the appropriate places.

In the urls list, create a list for the ad renderer that will use the ID (or use the get parameter for this).

And in the generation of links on the list page, use the tag url.

This is if in general terms. The question is too broad and the answer will have to write almost the entire application code, so that it is with examples.

 1
Author: Константин Комиссаров, 2020-12-02 10:07:25