gpt4 book ai didi

python - Django错误: takes 0 positional arguments but 1 was given

转载 作者:太空宇宙 更新时间:2023-11-03 17:52:45 24 4
gpt4 key购买 nike

我正在尝试在 EC2 ubuntu 实例上设置 django。

在我看来,我有:

from django.shortcuts import render, HttpResponse
import requests


def test(request):
return HttpResponse('hi')

urls.py 有:

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'tp.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^index/$', 'tp1.views.index', name='index'),
url(r'^test/$', 'tp1.views.test', name='test'),

# url(r'^admin/', include(admin.site.urls)),
)

我收到上面的错误。我做错了什么?

编辑;

 Environment:    


Request Method: GET
Request URL: http://52.10.**-**:8000/test/

Django Version: 1.7.5
Python Version: 3.4.0
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tp1')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)

Exception Type: TypeError at /test/
Exception Value: test() takes 0 positional arguments but 1 was given

最佳答案

您问题中的代码看起来不错,但 test() View 函数采用一个位置参数(request),因此代码您的问题中不是引发该异常的代码。

您是否遗漏了任何代码(也许您稍后在 views.py 文件中重新定义了 test)?该代码是来自 tp1/views.py 或其他文件的顶部吗?

关于python - Django错误: takes 0 positional arguments but 1 was given,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28907667/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com