Generating a url to WeekArchiveView from template

I’ve build an archive view using the generic date view ‘WeekArchiveView’ and this works by providing the variables directly in the URL - ie localhost:8000/2022/week/4 however I’m wanting to create a link to this from my index page.

<a href="{% url 'archive_week' 2022 04 %}"> Week View</a> works fine but this is obviously hard coded.

Any help on how I can get the current year, and week of the year as a variable in the above context? Can this be done in the template, or does it needed to be passed from the view. In what I consider to be a little unhelpful, the docs say " Therefore, you should avoid using [ date ] to generate URLs for WeekArchiveView" but not what to use!

Cheers

The conclusion I draw from the full context of that section in the docs is that since:

The week_format attribute is a strptime() format string used to parse the week number.

and

Keep in mind that week numbers computed by the date template filter with the 'W' format character are not always the same as those computed by strftime() and strptime() with the '%W' format string.

That you would want to use the strftime function in your view.

That also leads me to believe that unless you create a custom tag, you would need to pass it into the template from the view.

You have another option as well. If you want to have a link to the current week (or previous week) without creating a link every time the page is rendered, you could map a url to a view that calculates the current week number and then calls the appropriate view, passing the calculated value.