我在本地计算机上运行 python-django 服务器
使用 django.urls 我尝试定义一个包含文件夹和文件的服务器路径
我的代码:
urls.py:
from django.urls import path
urlpatterns = [
path("", server.views.index, name="index"),
path("imageSaved/<str:folder>/<str:picture>", server.views.imageSaved, name="imageSaved")
]
我也试试:
path("imageSaved/<path:path>", server.views.imageSaved, name="imageSaved")
我得到了同样的错误。
imageSaved 功能来自 server.views:
def imageSaved(request):
res=request.__str__()
return HttpResponse(res)
因为路径是一个字符串,所以我这样定义它:<str:folder>/<str:picture>
当我写一个网址时:
http://localhost:5000/imageSaved/fff/ddd
我收到错误:
TypeError at /imageSaved/dd/dd
imageSaved() got an unexpected keyword argument 'folder'
回溯是:
Environment:
Request Method: GET
Request URL: http://localhost:5000/imageSaved/dd/dd
Django Version: 3.1rc1
Python Version: 3.8.5
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'server']
Installed Middleware:
('whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback (most recent call last):
File "Local\Programs\Python\Python38\lib\site-packages\django-3.1rc1-py3.8.egg\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "Local\Programs\Python\Python38\lib\site-packages\django-3.1rc1-py3.8.egg\django\core\handlers\base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
Exception Type: TypeError at /imageSaved/dd/dd
Exception Value: imageSaved() got an unexpected keyword argument 'folder'
谢谢!!
芜湖不芜
相关分类