/index/'tab11'处的NoReverseMatch不是有效函数

2024-06-25 05:30:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我用了1*1 tab11.html在我的应用程序story/templates/story/tab11.html中 如果我使用path('index/tab11.html/',views.tab11,name='tab11'),它在

views.tab11只包含一行返回render(request,tab11.html)

请帮我解决这个问题,这样我的url索引/tab11就可以得到输出了

url文件是:path('index/tab11/',views.tab11,name='tab11') 但我在索引中找到了NoReverseMatch。与“tab11”相反,找不到tab11'不是有效的视图函数或模式名称

我的回溯是:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/index/

Django Version: 2.1.7
Python Version: 3.5.0
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'allauth.socialaccount.providers.google',
 'story',
 'pages',
 'users']
Installed Middleware:
['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']


Template error:
In template D:\Yashvi_Django\Imagualization_copy\story\templates\story\create_9.html, error at line 80
   Reverse for 'tab11' not found. 'tab11' is not a valid view function or pattern name.
   70 :             <div class="container">
   71 : 
   72 : </div>
   73 : <h2 align="center">Select the Cell Layout for your Story/poem:</h2>
   74 :                     
   75 :                     <table align="center">
   76 :                     <!-- Row 1-->
   77 :                     <tr>
   78 :                     
   79 :                     <td >
   80 :                         <div class="divclass" id="div1" ><h2 id="tab1"><a href= {% url 'tab11' %} >1*1</a></h2></div>
   81 :                     </td>
   82 :                     <td >
   83 :                         <div class="divclass" id="div2"><h2 id="tab21"><a href="tab21.html">2*1</a></h2></div>
   84 :                     </td>
   85 :                     <td>
   86 :                         <div class="divclass" id="div3"><h2 id="tab31"><a href="tab31.html">2*1</a></h2></div>
   87 :                     </td>
   88 :                     </tr>
   89 :                     <!-- Row 2-->
   90 :                     <tr>


Traceback:

File "C:\Users\DELL\.virtualenvs\Imagualization_copy-dFO-jx_p\lib\site-packages\django\core\handlers\exception.py" in inner
  34.             response = get_response(request)

File "C:\Users\DELL\.virtualenvs\Imagualization_copy-dFO-jx_p\lib\site-packages\django\core\handlers\base.py" in _get_response
  126.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\DELL\.virtualenvs\Imagualization_copy-dFO-jx_p\lib\site-packages\django\core\handlers\base.py" in _get_response
  124.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "D:\Yashvi_Django\Imagualization_copy\story\views.py" in index
  73.     return render(request,'story/create_9.html')

File "C:\Users\DELL\.virtualenvs\Imagualization_copy-dFO-jx_p\lib\site-packages\django\shortcuts.py" in render
  36.     content = loader.render_to_string(template_name, context, request, using=using)

File "C:\Users\DELL\.virtualenvs\Imagualization_copy-dFO-jx_p\lib\site-packages\django\template\loader.py" in render_to_string
  62.     return template.render(context, request)

File "C:\Users\DELL\.virtualenvs\Imagualization_copy-dFO-jx_p\lib\site-packages\django\template\backends\django.py" in render
  61.             return self.template.render(context)

File "C:\Users\DELL\.virtualenvs\Imagualization_copy-dFO-jx_p\lib\site-packages\django\template\base.py" in render
  171.                     return self._render(context)

File "C:\Users\DELL\.virtualenvs\Imagualization_copy-dFO-jx_p\lib\site-packages\django\template\base.py" in _render
  163.         return self.nodelist.render(context)

File "C:\Users\DELL\.virtualenvs\Imagualization_copy-dFO-jx_p\lib\site-packages\django\template\base.py" in render
  937.                 bit = node.render_annotated(context)

File "C:\Users\DELL\.virtualenvs\Imagualization_copy-dFO-jx_p\lib\site-packages\django\template\base.py" in render_annotated
  904.             return self.render(context)

File "C:\Users\DELL\.virtualenvs\Imagualization_copy-dFO-jx_p\lib\site-packages\django\template\defaulttags.py" in render
  442.             url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)

File "C:\Users\DELL\.virtualenvs\Imagualization_copy-dFO-jx_p\lib\site-packages\django\urls\base.py" in reverse
  90.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))

File "C:\Users\DELL\.virtualenvs\Imagualization_copy-dFO-jx_p\lib\site-packages\django\urls\resolvers.py" in _reverse_with_prefix
  622.         raise NoReverseMatch(msg)

Exception Type: NoReverseMatch at /index/
Exception Value: Reverse for 'tab11' not found. 'tab11' is not a valid view function or pattern name.

Tags: djangoinpylibsitevirtualenvsrenderusers