Django Urls-模板问题{%url''%}

问题描述 投票:0回答:1

[当我启动Django时,我使用1.11,从那以后升级到2.0。我的网址正常工作,没有任何问题,我可以想象某些内容已更新,但我不断浏览文档,看不到问题出在哪里。从我看到的模板中,我的网址是正确的,即使我也尝试过使用''并仍然遇到相同的问题。

NoReverseMatch at /admin/dashboard
Reverse for '' not found. '' is not a valid view function or pattern name.
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/dashboard
Django Version: 2.2.6
Exception Type: NoReverseMatch
Exception Value:    
Reverse for '' not found. '' is not a valid view function or pattern name.
Exception Location: /home/bridgetsarah/.local/lib/python3.5/site-packages/django/urls/resolvers.py in _reverse_with_prefix, line 673
Python Executable:  /usr/bin/python3
Python Version: 3.5.2
Python Path:    
['/home/bridgetsarah/voyage/bridgetsarah',
 '/usr/lib/python35.zip',
 '/usr/lib/python3.5',
 '/usr/lib/python3.5/plat-x86_64-linux-gnu',
 '/usr/lib/python3.5/lib-dynload',
 '/home/bridgetsarah/.local/lib/python3.5/site-packages',
 '/usr/local/lib/python3.5/dist-packages',
 '/usr/lib/python3/dist-packages']
Server time:    Fri, 25 Oct 2019 19:26:43 +0000

任何信息,将不胜感激。

      <ul>
24      <li> <i class="fas fa-tachometer-alt"></i>  <a href="#"> Dashboard </a> </li>
25      <li><i class="fas fa-tasks"></i>  <a href='#'> Projects </a> </li>
26      <li><i class="fas fa-users"></i> <a href="{% url client %}"> Clients </a> </li>
27      <li><i class="fas fa-server"></i><a href='#'> Servers </a> </li>
28    </ul>  
29  
from django.urls import include, path , re_path
from django.conf.urls import  include, url
from . import views
from django.contrib.auth.views import LoginView
from voyage.views import login_invalid, dashboard, client


app_name = 'voyage'

urlpatterns = [


    # Clients---------------------------------- #
    path('admin/client', views.client, name='client'),]
def client(request):
    return render(request, 'admin/client/client.html', context)

如果有人可以指出正确的方向,将不胜感激!

python html django python-3.x django-urls
1个回答
0
投票

应该为{% url "client" %}-名称必须用引号引起来。

[注意,这在Django 1.5(2012年)中就一路改变了;这绝对不会在1.11版中起作用。

© www.soinside.com 2019 - 2024. All rights reserved.