namespacing modelview

In my url.py I have:

app_name = "showorderofplay"
urlpatterns = [
    path("", views.index, name="index"),
    path("<int:association_id>/events/", views.events, name="events"),
    path("<int:association_id>/create_event/", views.EventCreate.as_view(), name="eventcreate"),
    path("<int:event_id>/event/", views.order, name="order"),
    
]

and in my template I have:

<a href="{% url 'showorderofplay:eventcreate' association.id %}" class="btn btn-primary">Create Event</a></div>

but I keep getting this error when I access the .as_view() url. The other namespacing work fine so I’m not sure what is wrong here?

text
Reverse for 'eventcreate' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<association_id>[0-9]+)/create_event/\\Z']

First a side note: The three backtick characters must be lines by themselves. They must not be part of any other line.

This is not an issue with the template or the url definition, the problem is in the view.

The root cause of this error is that the association.id is either blank, null, or undefined. Without seeing the view that is trying to render this template, we cannot diagnose this further.

It’s the same view as my other topic on validating user access :grimacing:

def events(request, association_id):

    association = Association.objects.filter(pk=association_id).first()

    events_list = Event.objects.filter(
        association=association_id, active=True, when__gt=event_past_date).order_by("when")

    context = {
        "active_events_list": events_list,
        "can_add_edit": request.user.has_perm('check_in_association', association),
    }
    return render(request, "showorderofplay/events.html", context)

I’m trying to add the url for a button on the event page so I can then open the template for EventCreate

Your template references a variable named association.

Your context shows that you’re only supplying active_events_list and can_add_edit as variables.

Is that template line you showed inside a loop where association is being defined?
We need to see more of that templates.

Thank you - I wasn’t passing association_id via context and furthermore had put association.id within the url. Now working :tada: