我将此功能放在views.py
:
def index(request):
return HttpRequest('Hello Ahmed')
我将其包含在urls.py
中,如下所示:
from django.contrib import admin
from django.urls import path
from first_app import views
urlpatterns = [
path('', views.index, name='index'),
path('admin/', admin.site.urls),
]
但是当我转到网址时,它会给我这个问题:
TypeError at /
__init__() takes 1 positional argument but 2 were given
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 2.0.1
答案 0 :(得分:1)
您的观点应该返回回复,而不是请求。
Copy
答案 1 :(得分:0)
而不是:
urlpatterns = [
path('', views.index, name='index'),
path('admin/', admin.site.urls),
]
试试这个:
urlpatterns = [
path(r'^$', views.index, name='index'),
path('admin/', admin.site.urls),
]