Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse for '' not found. '' is not a valid view function or pattern name - DJANGO

Tags:

python

django

I have this error:

NoReverseMatch at / Reverse for 'peliculas' not found. 'peliculas' is not a valid view function or pattern name. Request Method: GET Request URL: http://127.0.0.1:8000/ Django Version: 2.1.2 Exception Type: NoReverseMatch Exception Value:
Reverse for 'peliculas' not found. 'peliculas' is not a valid view function or pattern name. Exception Location: C:\Users\Angel\AppData\Local\Programs\Python\Python37\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 622 Python Executable: C:\Users\Angel\AppData\Local\Programs\Python\Python37\python.exe Python Version: 3.7.1 Python Path:
['C:\Users\Angel\Desktop\Trabajos\Videoclub\videoclub_django', 'C:\Users\Angel\AppData\Local\Programs\Python\Python37\python37.zip', 'C:\Users\Angel\AppData\Local\Programs\Python\Python37\DLLs', 'C:\Users\Angel\AppData\Local\Programs\Python\Python37\lib', 'C:\Users\Angel\AppData\Local\Programs\Python\Python37', 'C:\Users\Angel\AppData\Local\Programs\Python\Python37\lib\site-packages']

I just dont get what's happening

You can see full code here:

https://github.com/AngelQuesada/videoclub_django

This is the part where it fails (base_generic.html)

            <div class="collapse navbar-collapse" id="navbarNavDropdown">
            <ul class="navbar-nav">
                <li class="nav-item active">
                    <a class="nav-link" href="{% url 'index' %}">Inicio
                        <span class="sr-only">(current)</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="{% url 'peliculas' %}">Peliculas</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Directores</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Actores</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Géneros</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="http://127.0.0.1:8000/admin/">Administración</a>
                </li>
            </ul>
        </div>

My urls.py file:

from django.contrib import admin
from django.urls import path, include, re_path
from django.conf.urls import url

from . import views

app_name = "videoclub"

urlpatterns = [
    path('', views.index, name="index"),
    url(r'^peliculas/$', views.PeliculaListView.as_view(), name='peliculas'),
    # url(r'^pelicula/(?P<pk>\d+)$', views.DetailPeliculaView.as_view(), 
    name='detalle-pelicula'),
]

Thanks in advance guys!

like image 283
AngelQuesada Avatar asked Nov 02 '18 00:11

AngelQuesada


Video Answer


1 Answers

You've namespaced your URLs in the videoclubs app. So rather than just {% url 'peliculas' %} you should use {% url 'videoclub:peliculas' %}

like image 118
Robin Zigmond Avatar answered Oct 11 '22 15:10

Robin Zigmond