请协助找出解决此错误的方法。
课程/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})
管理员/视图.py
from django.shortcuts import render
def hello_world(request):
return render(request, 'home.html')
管理网址.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'),
]
课程/ urls.py
from django.urls import path
from . import views
urlpatterns=[
path('',views.course_list, name="listofcourses"),
]
现在在运行服务器上,我收到此错误
hello_world() 缺少 1 个必需的位置参数:“请求”
我希望在 127.0.0.1:8000 上的运行服务器上发布主页,在 127.0.0.1:8000/courses 上发布课程页面
先感谢您
您正在调用(执行)urls 中的视图,这是不应该的。你可以这样做:
path('hello-world/', views.hello_world), # don't use 'admin/' because you already have url configured against this path.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句