Python 获取正确url和正确参数的NoReverseMatch
我已经仔细阅读了我的代码,但我仍然停留在这一点上,我得到了正确的url和正确的参数的NoReverseMatch错误 这是我的URLConfigPython 获取正确url和正确参数的NoReverseMatch,python,django,Python,Django,我已经仔细阅读了我的代码,但我仍然停留在这一点上,我得到了正确的url和正确的参数的NoReverseMatch错误 这是我的URLConfig url(r'profile/$', views.agent_profile, name='agent_profile'), url(r'profile/(?P<pk>[A-Za-z0-9]+)/$', views.change_profile, name='change_profile'), url(r'a
url(r'profile/$', views.agent_profile, name='agent_profile'),
url(r'profile/(?P<pk>[A-Za-z0-9]+)/$', views.change_profile, name='change_profile'),
url(r'assign/(?P<pk>[A-Za-z0-9]+)/profile/(?P<profile>[A-Za-z0-9]+)/$', views.assign_profile, name='assign_profile'),
模板中的url调用如下:
<li><a href={% url 'portfolio:assign_profile' pk=agent.code_agent profile="super_agent" %}>Super Agent</a></li>
NoReverseMatch at /portfolio/profile/1/
Reverse for 'assign_profile' with keyword arguments '{'pk': '1', 'profile': 'super_agent'}' not found. 1 pattern(s) tried: ['portfolio/assign/(?P<pk>[A-Za-z0-9]+)/profile/(?P<profile>[A-Za-z0-9]+)/$']
Request Method: GET
Request URL: http://localhost:8000/portfolio/profile/1/
Django Version: 1.11
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'assign_profile' with keyword arguments '{'pk': '1', 'profile': 'super_agent'}' not found. 1 pattern(s) tried: ['portfolio/assign/(?P<pk>[A-Za-z0-9]+)/profile/(?P<profile>[A-Za-z0-9]+)/$']
Exception Location: C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 497
Python Executable: C:\Users\admin\AppData\Local\Programs\Python\Python36\python.exe
Python Version: 3.6.1
Python Path:
['C:\\Users\\admin\\PycharmProjects\\trial',
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36\\python36.zip',
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36\\DLLs',
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36\\lib',
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36',
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-packages']
Server time: Wed, 3 Jan 2018 14:35:49 +0000
错误如下:
<li><a href={% url 'portfolio:assign_profile' pk=agent.code_agent profile="super_agent" %}>Super Agent</a></li>
NoReverseMatch at /portfolio/profile/1/
Reverse for 'assign_profile' with keyword arguments '{'pk': '1', 'profile': 'super_agent'}' not found. 1 pattern(s) tried: ['portfolio/assign/(?P<pk>[A-Za-z0-9]+)/profile/(?P<profile>[A-Za-z0-9]+)/$']
Request Method: GET
Request URL: http://localhost:8000/portfolio/profile/1/
Django Version: 1.11
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'assign_profile' with keyword arguments '{'pk': '1', 'profile': 'super_agent'}' not found. 1 pattern(s) tried: ['portfolio/assign/(?P<pk>[A-Za-z0-9]+)/profile/(?P<profile>[A-Za-z0-9]+)/$']
Exception Location: C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 497
Python Executable: C:\Users\admin\AppData\Local\Programs\Python\Python36\python.exe
Python Version: 3.6.1
Python Path:
['C:\\Users\\admin\\PycharmProjects\\trial',
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36\\python36.zip',
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36\\DLLs',
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36\\lib',
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36',
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-packages']
Server time: Wed, 3 Jan 2018 14:35:49 +0000
NoReverseMatch at/portfolio/profile/1/
找不到具有关键字参数“{pk':“1”,“profile':“super_agent”}”的“assign_profile”的相反内容。尝试了1种模式:[“投资组合/分配/(?P[A-Za-z0-9]+)/profile/(?P[A-Za-z0-9]+)/$”
请求方法:获取
请求URL:http://localhost:8000/portfolio/profile/1/
Django版本:1.11
异常类型:NoReverseMatch
异常值:
找不到具有关键字参数“{pk':“1”,“profile':“super_agent”}”的“assign_profile”的相反内容。尝试了1种模式:[“投资组合/分配/(?P[A-Za-z0-9]+)/profile/(?P[A-Za-z0-9]+)/$”
异常位置:C:\Users\admin\AppData\Local\Programs\Python\36\lib\site packages\django\url\resolvers.py in\u reverse\u带前缀,第497行
Python可执行文件:C:\Users\admin\AppData\Local\Programs\Python\Python36\Python.exe
Python版本:3.6.1
Python路径:
['C:\\Users\\admin\\pycharm项目\\trial',
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36\\Python36.zip',
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36\\DLLs',
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36\\lib',
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36',
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site packages']
服务器时间:2018年1月3日星期三14:35:49+0000
您有profile=“super_agent”
,但在您的正则表达式中,[A-Za-z0-9\]+
不包含下划线
url(r'assign/(?P<pk>[A-Za-z0-9]+)/profile/(?P<profile>[A-Za-z0-9_]+)/$', views.assign_profile, name='assign_profile'),
您有profile=“super_agent”
,但在regex[A-Za-z0-9\]+
中不包含下划线
url(r'assign/(?P<pk>[A-Za-z0-9]+)/profile/(?P<profile>[A-Za-z0-9_]+)/$', views.assign_profile, name='assign_profile'),