我坚持这个:< a href =" {%url' newapp:home' %}" > revWaves< / A>
错误讯息为:" NoReverseMatch"
反向' home()'参数'()'和关键字参数' {}'未找到。尝试了0种模式:[]
我为' newapp'创建了名称空间。并且url路径也是正确的,即/static/newapp/home.html及以上< a href =" {%url' newapp:home' %}"> revWaves< / A>进入header.html
所以我无法弄清楚错误是什么。请帮助。
Main Urls.py
from django.conf.urls import url , include
from django.contrib import admin
urlpatterns = [
url(r'^newapp/', include('newapp.urls', namespace='newapp')),
]
newapp urls.py
from django.conf.urls import url , include
from . import views
urlpatterns = [
url(r'^$',views.home) ,
url(r'^about$',views.about) ,
url(r'^services',views.service) ,
url(r'^customers',views.customer),
url(r'^contact',views.contact) ,
]
views.py
from django.shortcuts import render
# Create your views here.
def home(request) :
return render(request, 'newapp/home.html')
def about(request):
return render(request, 'newapp/about.html')
def service(request):
return render(request, 'newapp/services.html')
def customer(request):
return render(request, 'newapp/customers.html')
def contact(request):
return render(request, 'newapp/contact.html')
header.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Ady Rules</title>
<meta charset="utf-8"/>
{% load static %}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css?family=Satisfy" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="{% static "newapp/style.css" %}"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.js"></script>
<style>
h1.intro {
color: brown;
}
</style>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- logo --!>
<div class="navbar-header">
<a class="navbar-brand" href="{% url 'newapp:home' %}"> revWaves</a>
<div>
</div>
</head>
<body class="body" style="background-color:#f6f6f6">
{% block content %}
{% endblock %}
</body>
</html>
home.html
{% extends "newapp/header.html" %}
{% block content %}
<h2>Hey There ! How Ya Doin ? </h2>
<h2> Welcome to the world of Programming !!</h2>
<h1 class = "intro"> New Appppppppp !!!!!!</h1>
{% endblock %}