NoReverseMatch: Reverse for 'custom-model-add' with keyword arguments '{'model_name': ''}' not found. 1 pattern(s) tried: ['ekle/(?P<model_name>[^/]+)/\\Z']

I’m trying to creating my own custom-admin-panel for my website. I was trying to add an add button to my models but i am keep getting the same error as the topics title. Here are my views codes:

def dynamic_model_item_add(request, model_name):
  
    
    model_objects = model.objects.all()
    verbose_name = model._meta.verbose_name_plural
    model = apps.get_model("intern_app", model_name)
    if not model:
        raise Http404("Böyle bir model bulunamadı.")


    ModelForm = modelform_factory(model, fields="__all__")

    if request.method == "POST":
        form = ModelForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return redirect(reverse("custom-model-add", args=[model_name]))  # Başarıyla eklenince aynı sayfaya dön
    else:
        form = ModelForm()
    
    context = {
        "model_objects": model_objects,
        "model": model,
        "verbose_name": verbose_name,
        "model_name": model._meta.model_name,  
        "form": form, 
        "model_name": model_name,
    }


    return render(request, "intern_app/custom_admin_add_item.html",context)

My URLs:

path("yonetici-paneli/",custom_admin.admin_links,name="yonetici-paneli"),
    path("yonetici-paneli/<str:app_label>/<str:model_name>/",custom_admin.admin_links_pages,name = "yonetici_paneli_sayfa"),

    path("ekle/<str:model_name>/", custom_admin.dynamic_model_item_add, name="custom-model-add"),

Welcome @EnisDBZ !

Side Note: When posting code here, enclose the code between lines of three
backtick - ` characters. This means you’ll have a line of ```, then your code,
then another line of ```. This forces the forum software to keep your code
properly formatted. (I have taken the liberty of correcting your original posts.
Please remember to do this in the future.)

Also, when requesting help with an error, please do not post the error as the title. Post the full error (with the traceback if any) in the body of the post. Use the title as a short summary of the error.

This error is usually telling you that the parameter you are trying to use with that url is null.

We’d need to see more details about where and how this error is being generated. Please post the complete error with the traceback as shown in the console screen. (Do not post a screenshot of the web page with the error.)

1 Like

Thanks for giving your time to me. I figure out the problem. I was forgetting to add app_label and model_name to two different functions. That was the problem lol.