TypeError: __init__() takes 1 positional argument but 2 were given( "GET /%3Cint:pk%3E.pk HTTP/1.1" 500 61744)
TypeError: __init__() takes 1 positional argument but 2 were given( "GET /%3Cint:pk%3E.pk HTTP/1.1" 500 61744)
需要帮助。我似乎无法解决这个问题。这里是 Django 的新手。
Traceback (most recent call last):
File "C:\Users\hanya\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\hanya\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\hanya\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
TypeError: __init__() takes 1 positional argument but 2 were given
模板
<h1><a href="{% url 'details' Testimony.pk %}">{{testimony.Title}}</h1>
urls.py
urlpatterns = [
...
re_path('<int:pk>/', views.detail, name='details'),
]
views.py
def details(self, pk):
print('1')
Testimony=get_object_or_404(Testimony, pk= pk)
print('2')
return render(request, 'details.html', {'Testimony': Testimony})
<int:pk>
应与 path
一起使用,而不是 re_path
。
path('<int:pk>/', views.detail, name='details'),
需要帮助。我似乎无法解决这个问题。这里是 Django 的新手。
Traceback (most recent call last):
File "C:\Users\hanya\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\hanya\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\hanya\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
TypeError: __init__() takes 1 positional argument but 2 were given
模板
<h1><a href="{% url 'details' Testimony.pk %}">{{testimony.Title}}</h1>
urls.py
urlpatterns = [
...
re_path('<int:pk>/', views.detail, name='details'),
]
views.py
def details(self, pk):
print('1')
Testimony=get_object_or_404(Testimony, pk= pk)
print('2')
return render(request, 'details.html', {'Testimony': Testimony})
<int:pk>
应与 path
一起使用,而不是 re_path
。
path('<int:pk>/', views.detail, name='details'),