Python Django url dispatcher调用了错误的函数
我的问题是: 我在我的Python Django url dispatcher调用了错误的函数,python,django,url,routing,Python,Django,Url,Routing,我的问题是: 我在我的urls.py文件中创建了一个新的re_路径,但是当我在该url上发出请求时,调用了错误的函数 # myapp/urls.py from django.urls import path, re_path from . import views as multiplayer_lite_views urlpatterns = [ # other paths re_path(r'vote/(?P<match_id>\w{16})', multipl
urls.py
文件中创建了一个新的re_路径
,但是当我在该url上发出请求时,调用了错误的函数
# myapp/urls.py
from django.urls import path, re_path
from . import views as multiplayer_lite_views
urlpatterns = [
# other paths
re_path(r'vote/(?P<match_id>\w{16})', multiplayer_lite_views.vote, name='multiplayer_lite_vote'),
re_path(r'nightvote/(?P<match_id>\w{16})', multiplayer_lite_views.night_vote, name='multiplayer_lite_night_vote'),
path('new-match/', multiplayer_lite_views.new_match, name='multiplayer_lite_new_match'),
path('', multiplayer_lite_views.home, name='multiplayer_lite_home'),
]
# myapp/views.py
def vote(request, match_id):
print('vote function')
# do other stuff
return return JsonResponse(...)
def night_vote(request, match_id):
print('nightvote function')
# do other stuff
return return JsonResponse(...)
在服务器端,我看到的是:
...
vote function
[18/Mar/2020 10:19:16] "POST /nightvote/gfvkpvhlwlqzosae HTTP/1.1" 200 16
...
PS我已经尝试关闭Django并重新打开,vs代码也是如此。如下更改您的url路径:
re_path(r'^vote/(?P<match_id>\w{16})$', multiplayer_lite_views.vote, name='multiplayer_lite_vote'),
re_path(r'^nightvote/(?P<match_id>\w{16})$', multiplayer_lite_views.night_vote, name='multiplayer_lite_night_vote'),
re_path(r'^vote/(?P\w{16})$”,多人_lite_views.vote,name='multiplayer_lite_vote'),
re_path(r'^nightvote/(?P\w{16})$),多人_lite_views.night_vote,name='multiplayer_lite_night_vote'),
我有这个问题,这是因为^