[Answered ]-How to update model fields from views with values from a href/url?

1👍

The path will try to find patterns that have ints for user_id and event_id if you do this:

# urls.py

urlpatterns = [
    ...
    path('update-event/<int:user_id>/<int:event_id>/',web_views.update_event,name='update-event'),
    ...
]

Then in your view, you can grab those, but they must have the same names you gave them in the url patterns, like this:

# views.py
def update_event(request, user_id, event_id):
    user= User.objects.get(id=user_id)
    ev=Event.objects.get(id=event_id)
    ...

Then your html url anchor tage will pass these two ints, in order:

<a href="{% url 'update-event' user.id event.id %}">

Leave a comment