Urls designing: i didnt understand documentation

from django.urls import path

from . import views

urlpatterns = [
path(‘articles/int:year/’, views.year_archive)

Here “articles” in paths,
Is article a variable or file name or class, class is with uppercase c". In documentation there is nothing.
Ok in modules Article is a class containing information. How “article” in urlpattern is path.

It’s neither - none of the above. It’s just text in the url that is used to match a pattern to decide what view to call. You could put pretty much anything there, and as long as that’s the url you supply, it’ll work.

You could define it as
path('qwerty/<int:year>/', views.year_archive)
and if you’re testing it using runserver on port 8000, you could enter this url and it would work:
http://localhost:8000/qwerty/2020/

In fact, you could have both lines in your pattern and they would both work.

As a side note, when you’re posting code here, please enclose the code between lines of three backtick - ` characters. This will preserve the formatting of the code, which is critical with a space-sensitive language such as Python.

This means you’ll have a line of ```, followed by your lines of code, followed by another line of ```.

For example:

# The line above this is ```
def function(self):
    return self
# The line below this is ```

If you’re entering just a single line like I did at the top, use a single backtick at the beginning and end of that line.

1 Like

Oh! Thats just any text.
Ok i will be sure to use ```
Thank you.