简体   繁体   English

Django 网址 - 模板问题 {% url '' %}

[英]Django Urls - Template Issue {% url '' %}

When I started Django I used 1.11 and since then upgraded to 2.0.当我开始 Django 时,我使用了 1.11,然后升级到了 2.0。 My URLs worked and had no problems and I would imagine something has been updated but I keep going over the documentation and I can't see where the issue is.我的 URL 工作正常,没有问题,我想有些东西已经更新了,但我一直在查看文档,我看不出问题出在哪里。 From what I've seen my URL in template is correct, even though I have also tried with '' and still get the same issue.从我所看到的模板中的 URL 是正确的,即使我也尝试过使用 '' 并且仍然遇到同样的问题。

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)

What can I try next?接下来我可以尝试什么?

It should be {% url "client" %} - the name must be in quotes.它应该是{% url "client" %} - 名称必须用引号引起来。

Note, this changed all the way back in Django 1.5 (in 2012);请注意,这在 Django 1.5(2012 年)中一直发生变化; this definitely wouldn't have worked in version 1.11.这在 1.11 版中绝对行不通。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM