I want to have 2 URLs
localhost:8000/events
localhost:8000/events/past
<a href="{% url 'events' %}">Upcoming Events</a>
<a href="{% url 'events' 'past' %}">Past Events</a>
def events(request, timeline='current'):
return render(request, 'events.html')
But my regular expression is incorrect :
re_path(r'^events(/(?P<timeline>[^/]+)?)?$', views.events, name='events'),
Is there no simpler way ?
Create two different url entries for the same view but with two different names.
I had to do :
path('events/past', views.events, kwargs = { 'timeline': 'past' }, name='events_past'),
path('events', views.events, name = 'events'),
But I was hoping for a one-liner regex.
I’d have taken a different approach.
I would have identified these urls as /events/current/
and /events/past/
allowing me to define the url as path('events/<str:timeline>/', views.events, name='events')
making the two urls more consistent with each other.