Please assist figuring out solution to this error.
courses/ views.py
from django.http import HttpResponse
from django.shortcuts import render
from .models import Course
def course_list(request):
courses = Course.objects.all()
return render(request, 'courses/course_list.html',{'courses':courses})
admin/ views.py
from django.shortcuts import render
def hello_world(request):
return render(request, 'home.html')
admin urls.py
from django.contrib import admin
from django.urls import path
from courses import views
from django.conf.urls import include
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('admin/', views.hello_world()),
path('courses/', include('courses.urls')),
path('courses/', views.course_list(), name='listofcourses'),
]
courses/ urls.py
from django.urls import path
from . import views
urlpatterns=[
path('',views.course_list, name="listofcourses"),
]
Now on running server, i am getting this error
hello_world() missing 1 required positional argument: 'request'
I wish to publish homepage on running server at 127.0.0.1:8000 and courses page on 127.0.0.1:8000/courses
Thank you in advance
You are calling(executing) the views in urls, which shouldn't do. You can do it like this:
path('hello-world/', views.hello_world), # don't use 'admin/' because you already have url configured against this path.