I have been stuck on this Django error for a while:
tutorials() missing 1 required positional argument: 'tutorial_id'
Below are the files. Using Python 3.5 and Django 1.10.
tutorials/urls.py:
from django.conf.urls import url
from . import views
app_name = 'tutorials'
urlpatterns = [
url(r'^(?P<tutorial_id>[0-9]+)/$', views.tutorials, name='tutorials'),
url(r'^$', views.tutorials, name='tutorials'),
]
tutorials/views.py
from django.shortcuts import render, get_object_or_404
from .models import Tutorial, Lesson
def tutorials(request, tutorial_id):
tutorials = get_object_or_404(Tutorial, pk=tutorial_id)
return render(request, 'tutorials/tutorials.html', { 'tutorials': tutorials})
When I visit website.com/tutorials
I get the error but it will work fine if I go to website.com/tutorials/1
which is good. But I want to be able to access /tutorials
so I can ad information to this link.
Perhaps you need different functions to serve a collection of tutorials and a single tutorial.
tutorials/urls.py
tutorials/views.py
Your need to create a separate template for a single tutorial view.