hello_world()缺少1个必需的位置参数:“ request”

时间:2018-12-01 07:58:24

标签: python django django-2.0

请协助找出解决此错误的方法。

课程/ 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')

管理员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'),
]

课程/ urls.py

from django.urls import path
from . import views

urlpatterns=[
path('',views.course_list, name="listofcourses"),
]

现在在运行的服务器上,出现此错误

hello_world()缺少1个必需的位置参数:“ request”

我希望在127.0.0.1:8000的运行服务器上发布主页,并在127.0.0.1:8000/courses的课程页面上发布

提前谢谢

1 个答案:

答案 0 :(得分:2)

您正在调用(执行) URLs 中的视图,这是不应该的。您可以这样做:

path('hello-world/', views.hello_world),   # don't use 'admin/' because you already have url configured against this path.