2

I'm doing tutorial "Movie rental" and i got error. Using the URLconf defined in vidly.urls, Django tried these URL patterns, in this order:

 Using the URLconf defined , Django tried these URL patterns, in this order:
1.admin/
2.movies/ [name='movie_index']
3.movies/ <int:movie_id [name='movie_detail']
The current path, movies/1, didn't match any of these.

my code is(from main urls.py):

from django.contrib import admin
from django.urls import path, include


urlpatterns = [
    path('admin/', admin.site.urls),
    path('movies/', include('movies.urls'))
]

from mysite i.e movies(urls.py)

from . import views
from django.urls import path

urlpatterns = [
    path('', views.index, name='movie_index'),
    path('<int:movie_id', views.detail, name='movie_detail')

]

from views.py

from django.shortcuts import render
from django.http import HttpResponse
from .models import Movie

def index(request):
    movies = Movie.objects.all()
    return render(request, 'movies/index.html', {'movies': movies})

def detail(request, movie_id):
    return HttpResponse(movie_id)

What i'm doing wrong?

Darkness
  • 155
  • 2
  • 13

2 Answers2

3

In your movies.urls you forgot to close URL parameter.

path('<int:movie_id>/', views.detail, name='movie_detail')

Instead you did,

path('<int:movie_id', views.detail, name='movie_detail')
Hisham___Pak
  • 1,472
  • 1
  • 11
  • 23
3

You're missing a closing >/.

path('<int:movie_id>/', views.detail, name='movie_detail')
onosendi
  • 1,889
  • 1
  • 7
  • 14