NoReverseMatch

Hey,

I’ve made a HTML Site which includes a ModelForm

<h1>Add new Blog</h1>
<form action="{% url 'job_create' %}" method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <button class="button" type="submit">Job erstellen</button>

</form>

on the Debug Site is says that there isnt a view with the name “job_create” but there is

views:

def job_create(request):
    if request.method == 'POST':
        form = JobForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('home:job_create')
    else:
        form = JobForm()
    return render(request,
                  'home/job_create.html',
                  {'form': form}

                  )

i’ve used this tutorial just with my code Django - ModelForm Tutorial (New) - YouTube

thanks for your help

Please post the exact and complete traceback of the error you are receiving.

When posting a traceback, also enclose it between the lines of three backticks.

django.urls.exceptions.NoReverseMatch: Reverse for 'job_create' not found. 'job_create' is not a valid view function or pattern name.

So, looking at this message:

It shows two possibilities here, not just one.

For this to be valid:

means you need to have the appropriate entry in your urls.py file for your home app.

What does that urls.py file look like?


from django.urls import path

from . import views
app_name = 'home'
urlpatterns = [
    path('', views.index, name="home"),
    path('adjust/', views.adjust_view, name="adjust"),
    path('offers/', views.offers_view, name="offers"),
    path('contact/', views.contact_view, name="contact"),
    path('login/', views.login_view, name="login"),
    path('register/', views.register_view, name="register"),
    path('logout/', views.logout_view, name="logout"),
    path('createjob/', views.job_create, name="job_create"),

]

Ahh - the issue may be here:

Try:
<form action="{% url 'home:job_create' %}" method="post">

It works! Ken you’re a genius!

Thanks for your help