我正在编辑模板以包含一个超链接。但是当我这样做的时候,我得到了NoReverseMatch错误。
与“views.hello_world”相反,没有找到参数'()‘和关键字参数'{}’。0已尝试的模式:[]
模板文件:
layout.html
{% load static from staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{% static 'css/layout.css' %}">
</head>
<body>
<div class="site-container">
<nav>
<a href="{% url 'views.hello_world' %}">Home</a> [**Error here**]
</nav>
{% block content %}{% endblock %}
</div>
</body>
</html>urls.py
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from . import views
urlpatterns = [
url(r'^courses/', include('courses.urls')),
url(r'^admin/', admin.site.urls),
url(r'^$', views.hello_world)
]
urlpatterns+=staticfiles_urlpatterns()views.py
from django.shortcuts import render
def hello_world(request):
return render(request, 'home.html')这行,回家的时候,我没有发现任何错误。但我补充说,NoReverseMatch出现了。我做错了什么?
发布于 2016-09-14 17:03:45
您需要给URL一个名称,并在url标记中引用该名称。
url(r'^$', views.hello_world, name='hello_world')..。
<a href="{% url 'hello_world' %}">https://stackoverflow.com/questions/39495962
复制相似问题